向COM端口发送命令

时间:2015-08-22 13:43:15

标签: java comm

我有一个DateCS MP55 cashregister,我希望它打印一些行,但我不知道我需要向它发送什么命令以及如何。它在COM5上连接,基本上这就是我发送'1'命令。这是正确的方式吗?

 if (port_id.getPortType () == CommPortIdentifier.PORT_SERIAL)
                  {
                      System.out.println ("Serial port: " + port_id.getName ());
                  }
                  else if (port_id.getPortType () == CommPortIdentifier.PORT_PARALLEL)
                  {
                      System.out.println ("Parallel port: " + port_id.getName ());
                  } else
                      System.out.println ("Other port: " + port_id.getName ());

                  // Attempt to open it
                  try {
                      CommPort port = port_id.open ("PortListOpen",20);
                      System.out.println (port_id.getName()+" port opened successfully");
                      outputStream = port.getOutputStream();
                      String num = "1";
                      outputStream.write(num.getBytes());
                      port.close ();
                  }

这是我发现的关于打印“命令”的内容:

 P - print text:P,[logical number],______,_,__;[line 1];[line 2];[line 3];[line 4];[line 5];
If the line is empty, it is not printed out. If it contains only spaces, it will be printed as anempty line.
 MP-50 and MP-55 print out only the first line. The maximum number of symbolsper line is 24 for ECR and 30 for FP

所以我必须这样做吗? :

outputStream.write("P,[logical number],______,_,__;[line 1];[line 2];[line 3];[line 4];[line 5]".getBytes());

0 个答案:

没有答案