Author Topic: Problem with PUT using serial port  (Read 3007 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline GTC

  • Newbie
  • Posts: 49
  • Programmer's motto: *This* time it will work.
    • View Profile
Problem with PUT using serial port
« on: January 04, 2021, 05:20:49 am »
Having difficulty with PUT and serial COM port.

Need to send 5 bytes to a radio in the format: p1 p2 p3 p4 cmd

... where p1 to p4 are placeholder bytes which can be any value, and cmd is the hex byte value E7

The port is working fine as evidenced by use with two other applications which communicate back and forth with the radio via its serial port.

The code is:

Code: QB64: [Select]
  1.  
  2. OPEN "COM8:4800,N,8,2" FOR RANDOM AS #1
  3.  
  4. ...
  5.  
  6. CMD$ = "????E7"
  7. PUT #1, , CMD$

... and my port analyzer shows this is what is being sent:

Code: QB64: [Select]
  1. Characters: ..????E7          Hex:  06 00 3f 3f 3f 3f 45 37  

My question is: what are the hex 06 00 bytes doing here? I didn't send them and they are the reason the radio is not responding to the command.

06 00 appears to be a count of the following bytes ... which I do not want transmitted down the com port.

PS: this is what one of the successfully-operating applications outputs, and what I am trying to emulate (it's using zeros not ?, but that is not the issue -- as any character can fill p1 thru p4 as I said at the top of my post):

Code: QB64: [Select]
  1. Character: ....￧     Hex: 00 00 00 00 e7    
« Last Edit: January 04, 2021, 05:44:29 am by GTC »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Problem with PUT using serial port
« Reply #1 on: January 04, 2021, 09:00:24 am »
Try:

CMD$ = “????” + CHR$(&HE7)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline GTC

  • Newbie
  • Posts: 49
  • Programmer's motto: *This* time it will work.
    • View Profile
Re: Problem with PUT using serial port
« Reply #2 on: January 04, 2021, 09:17:06 am »
Try:

CMD$ = “????” + CHR$(&HE7)

That results in:

Code: QB64: [Select]
  1. Characters: ..????￧  Hex: 05 00 3f 3f 3f 3f e7  
 

... still with the 05 00 in front of the 5 bytes that I need. That is, a total of 7 bytes is being output by the PUT operation, whereas the radio only wants the rightmost 5 bytes.

Dunno how/why the 05 00 is being put in front of my string.

Marked as best answer by GTC on January 04, 2021, 04:40:55 am

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Problem with PUT using serial port
« Reply #3 on: January 04, 2021, 09:25:44 am »
I would guess the 05 00 is the size of the data that is being PUT.  Before, it was 06 for 6 bytes, and now it’s 05 for 5 bytes.

Try:

OPEN "COM8:4800,N,8,2" FOR BINARY AS #1
« Last Edit: January 04, 2021, 09:28:34 am by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline GTC

  • Newbie
  • Posts: 49
  • Programmer's motto: *This* time it will work.
    • View Profile
Re: Problem with PUT using serial port
« Reply #4 on: January 04, 2021, 09:33:03 am »

Try:

OPEN "COM8:4800,N,8,2" FOR BINARY AS #1

Doing that resulted in nothing meaningful being sent to the Com port.

Fixed! Thank you! :-)
« Last Edit: January 04, 2021, 09:37:46 am by GTC »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Problem with PUT using serial port
« Reply #5 on: January 04, 2021, 09:41:51 am »
In that case, I’d suggest since the first 2 bytes represent size, and since the radio doesn’t care about the first 4 bytes, I’d just send 3 bytes.

CMD$ = “??” + CHR$(&HE7)

When the radio gets it, it should read:  03 00 3f 3f e7

At least, I imagine it should.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline GTC

  • Newbie
  • Posts: 49
  • Programmer's motto: *This* time it will work.
    • View Profile
Re: Problem with PUT using serial port
« Reply #6 on: January 04, 2021, 09:51:43 am »
In that case, I’d suggest since the first 2 bytes represent size, and since the radio doesn’t care about the first 4 bytes, I’d just send 3 bytes.

CMD$ = “??” + CHR$(&HE7)

When the radio gets it, it should read:  03 00 3f 3f e7

At least, I imagine it should.

As per my previous (updated), your suggestion worked perfectly and I green ticked it. Binary mode doesn't output any 'header bytes' or whatever they are. (Fellippe?)

Very happy now as I can get on with the job, so many thanks, again.