I don’t know much about this, so this is going to be a pretty basic question.
I have a nifty little USB thing which emulates a COM port. It’s a simply switch, to which I can send three different signals: ON, OFF and GET STATUS
I’ve tested it using a terminal program called RealTerm. In this, I can open the port at the set baud rate and other options, and then send bin files to the port. When I got the thing, I also downloaded three different .bin files – one for ON, one for BREAK and one for GET STATUS. This works like a charm, and the port returns the corresponding codes etc.
Now, I’d like to try this in Java (first, then possibly C/C++). So I got a library called JSSC (v0.9), which makes this pretty easy. This is what I do:
public static void main(String[] args) {
String[] portNames = SerialPortList.getPortNames();
for(int i = 0; i < portNames.length; i++){
System.out.println(portNames[i]);
}
SerialPort serialPort = new SerialPort("COM10");
try {
serialPort.openPort();//Open serial port
serialPort.setParams(SerialPort.BAUDRATE_9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
serialPort.writeBytes("0x55 01 01 02 00 00 00 59".getBytes());
serialPort.closePort();
}
catch (SerialPortException ex) {
System.out.println(ex);
}
}
The baud rate, data and stop bits are the correct ones. When I plug in the device, the system.out.prinln lists the port, so it looks like the device is detected.
Now, the device has the following code words:
Make: 0x55 01 01 02 00 00 00 59
Break: 0x55 01 01 01 00 00 00 58
Check status: 0x55 01 01 00 00 00 00 57
Should I then just be able to pass those hex strings to the device in the java program, and get/observe the result(s)? If so, how do I do it? Just writeBytes() or writeString() like above doesn’t do anything. (I hear a click from the device when the MAKE or BREAK signal works).
Or is there a way to pass these .bin files to the port, like I do in RealTerm?
Also, does anyone know exactly what kind of files these .bin files might be? The guy I bought it from (cheaply) is not very informative, and doesn’t want to help with things or answer questions not direcly related to the device (which is understandable, of course).
I don’t need to delve into microprocessor programming or similar topics here, since I’m really just trying to accomplish some basic operations. But some insight or overview is of course necessary.
It seems to me, that those codes:
you have to send like byte-arrays. They look like hex numbers, so try to do this: