使用TCP / IP捕获梅特勒托莱多IND560的重量

时间:2018-12-18 01:07:08

标签: c# .net tcp-ip

我正在尝试使用C#的streamReader和streamWriter类从IND560捕获净重。似乎已建立连接,但是无论我发送的命令如何,我都会得到响应:83无法识别命令。我在IND560的Communications> Template> output下看到template1的命令(wt0111)。

下面的代码如果有人有什么建议可以帮助我前进,将不胜感激!

static void writeToStream(string cmd)
    {
        if (tcpClient.Connected)
        {
            Console.WriteLine("Sending CMD: {0}\\n", cmd);
            // tried with appending a \r, \n, and \r\n same result: 83 command not found
            clientStreamWriter.Write(cmd + '\n');

            clientStreamWriter.Flush();

        }

    }

以下是该程序的示例输出,显示了响应83:

enter image description here

1 个答案:

答案 0 :(得分:1)

您需要为此目的使用read命令(根据link here

Format: read SDV#1 SDV#2
Example 1: read wt0101 wt0103
Response 1: 00R003~ 17.08~lb~ 

所以,就您而言

read wt0101
read wt0111

根据您的情况,您需要在字段ID(wt0101)之前添加“ read”。

if (tcpClient.Connected)
{
  Console.WriteLine("Sending CMD: {0}\\n", cmd);
  clientStreamWriter.Write($"read {cmd}" + '\n');
  clientStreamWriter.Flush();
}

如果您打算支持更多命令,我建议为您的用户提供一个选项,以输入命令以“读取”,“写入”,“帮助”以及字段名称。