Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Serial port problems

The following code:
set port=COM6
set h=%@SERIALPORTOPEN[%port]
echo Handle %h
set result=%@SERIALPORTREAD[%h,0]
echo Read "%result"
set result=%@SERIALPORTCLOSE[%h]
echo Closed port %port (Handle %h) with result "%result"
produces the output:

0




(The second run is with the USB cable to COM6 unplugged).

At this stage, there are no characters in the serial buffer of it to read.
The returned value (result) from @SERIALPORTREAD seems to be 1 in every case. Is this an 'OK' result? If so, where are the read characters stored?

If the returned characters are also returned, how can you tell the difference between a return of 1 meaning it ran OK, and 1 meaning that a single digit 'one' was in the serial buffer?

We are reading a device that we are expecting to return a single digit, 1 or 0.

This looks like a bug, but it might be a 'how to'.
 
Different, but no better.
The 64-bit V17 SerialPortRead function simply returns what is inside the [ ].

So if 3931893 is a valid handle for a serial port, then
set result=%@SERIALPORTREAD[3931893,123456789]
sets result to 3931893,123456789
 
No, still struggling, and getting very frustrated by something that should be so simple. I just want to send two printable characters to a serial device, and read a single character reply that is 0 or 1 into an environment variable.
%@READSERIALPORT with a valid handle simply returns nothing. Blank.
Not getting far with SERIALPORTWRITE either for that matter.

The command:
echo ^rn1^r > COM6
turns relay 1 on. I can hear it click immediately.

Having turned the relay off again, the commands:
set port=COM6
set h=%@SERIALPORTOPEN[%port]
echo Handle %h
set result=%@SERIALPORTWRITE[%h,^rn1^r]
set result=%@SERIALPORTFLUSH[%h]
set result=%@SERIALPORTCLOSE[%h]
dont seem to do anything - I cannot hear a click.

So if this doesn't work, I don't stand any chance of getting characters back if the enquiry command isnt getting through.

If I use the 'echo' to send the enquiry through, I still get no joy on the read.

I have now spent 3 days on this, and I expected it to take less than an hour. This isn't even slightly funny any more.
 
Having turned the relay off again, the commands:
set port=COM6
set h=%@SERIALPORTOPEN[%port]
echo Handle %h
set result=%@SERIALPORTWRITE[%h,^rn1^r]
set result=%@SERIALPORTFLUSH[%h]
set result=%@SERIALPORTCLOSE[%h]
dont seem to do anything - I cannot hear a click.

I would be surprised if your @SERIALPORTOPEN works as you hope, since you didn't provide the baud, parity, bits, or flow control options. What is your serial device expecting for those options?
 
Your documentation doesn't say what happens if no baud, bits or parity is specified. So I assumed nothing, ie the current settings of the port are untouched.
But your settings dont work anyway.
Two runs of my script. One with [COM6,9600] and the other with just [COM6] as arg to @SERIALPORTOPEN.
upload_2014-10-28_10-50-11.png
 

Attachments

  • upload_2014-10-28_10-49-54.png
    upload_2014-10-28_10-49-54.png
    18.7 KB · Views: 200
Back
Top
[FOX] Ultimate Translator
Translate