1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Serial port problems

Discussion in 'Support' started by LowdhamStation, Oct 24, 2014.

  1. LowdhamStation

    Joined:
    Oct 16, 2014
    Messages:
    6
    Likes Received:
    0
    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:

    [​IMG]



    (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'.
     
  2. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    10,027
    Likes Received:
    84
  3. LowdhamStation

    Joined:
    Oct 16, 2014
    Messages:
    6
    Likes Received:
    0
    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
     
  4. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    10,027
    Likes Received:
    84
    There was a typo in @SERIALPORTREAD in 17.0.28 (referencing the wrong variable); it's been corrected in 17.0.29 (already uploaded). Please try the new build and let me know if it works for you.
     
  5. LowdhamStation

    Joined:
    Oct 16, 2014
    Messages:
    6
    Likes Received:
    0
    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.
     
  6. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    10,027
    Likes Received:
    84
    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?
     
  7. LowdhamStation

    Joined:
    Oct 16, 2014
    Messages:
    6
    Likes Received:
    0
    The line before, in the BTM file was mode com6,9600,n,8,1, but I didn't mention it as it didn't seem relevant.
     
  8. LowdhamStation

    Joined:
    Oct 16, 2014
    Messages:
    6
    Likes Received:
    0
    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
     

    Attached Files:

Share This Page