| Author |
QBASIC PRINT --> COM port OutputStream.write()
|
Ben Wood
Ranch Hand
Joined: Aug 14, 2001
Posts: 342
|
|
Hi ranchers. A quick question that someone with some QBASIC experience might be able to clear up v.quickly. I'm porting an old QBASIC program that communicates with a piece of scientific hardware over COM1 on a win pc. I can see from console output of both programs that the string I'm building for each command ready to send to the port is the same, yet the Java version doesn't get the right response - in fact it just get's a DLE (data link escape) followed by a NAK (negative acknowledge) response character every time. It struck me that maybe the Java... is doing something different to... ...i.e. maybe command.getBytes() is wrong, sending the message in the wrong format or something. I also wondered whether byte order might have any influence on the bytes sent/received. Any ideas about this gratefully received as this task is a little out of the ordinary for me and I'm out of my depth. Cheers. [ August 13, 2004: Message edited by: Ben Wood ] [ August 13, 2004: Message edited by: Ben Wood ]
|
SCJP 1.4, www.gsi3d.org.uk
|
 |
Ben Wood
Ranch Hand
Joined: Aug 14, 2001
Posts: 342
|
|
|
what about writing to a port from Java in ASCII mode...I think this may be the problem, but not sure how to go about it?
|
 |
Julian Kennedy
Ranch Hand
Joined: Aug 02, 2004
Posts: 823
|
|
I don't think byte order can have an influence unless you have more than one byte in a data type, e.g. short, int, etc. Since you're dealing with "byte" that's not a factor. I think it may be a charset issue. There's a version of String.getBytes() that takes a charset. The charset you use will have to be the same as used by the original software and as expected by the hardware. Jules
|
 |
Larry D. LeFever
Greenhorn
Joined: Aug 07, 2004
Posts: 6
|
|
|
how about flushing the stream?
|
 |
Ben Wood
Ranch Hand
Joined: Aug 14, 2001
Posts: 342
|
|
|
Cheers guys. I just tried the two suggestions and it didn't make any difference unfortunately. I think what I really need is an example Java application that can be used to send any command string to the device and read what comes back to see if I get the same result. Any pointers to such a test app?
|
 |
Julian Kennedy
Ranch Hand
Joined: Aug 02, 2004
Posts: 823
|
|
Originally posted by Ben Wood: I can see from console output of both programs that the string I'm building for each command ready to send to the port is the same
Have you tried writing out the binary (or hex) values for what you're actually sending? I think that it's possible for different things to look the same on the screen. Still kinda clinging on to the charset thing really, but if you are sending the exactly same thing I see no reason why you wouldn't be getting the same response. Jules
|
 |
Ben Wood
Ranch Hand
Joined: Aug 14, 2001
Posts: 342
|
|
I haven't tried that. I'll have a look into it, cheers. Arghhhhh, I really need to crack this one, it's winding me up..feels like
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12265
|
|
Perhaps the QBASIC also sends a <cr><lf> or similar line termination? Bill
|
 |
 |
|
|
subject: QBASIC PRINT --> COM port OutputStream.write()
|
|
|