SerialConnection Sending question

I need to send a series of bytes through a serial connection.
It could be an array of 21 integers values from 0 to 200+ (for example).
The receiving end is expecting little endian data.

I am creating a little endian memory block of the correct size, and packing the Uint8 values in.
Then I am converting to a string to send.

“Var Str As String = m.StringValue( 0, m.size)”

Does this seem correct?
It’s not behaving as I expect. And I am validating that there is no encoding on the string.


Seems to be ok. You create the MB, set the endiannes and then you can just Write the memoryblock since it’s the same as a string. So:

Var myMB As New MemoryBlock(1234)
myMB.LittleEndian = True 


Writing the memory block is a good idea. Thanks.
This still doesn’t seem to get the response I expect so I’m missing something else. I am always concerned when a communication protocol can take a variable length of input without a dedicated terminating code.

When they say no flow control, do I set all the other options to false? XON, CTS, DTR, etc?

You’l have to test and try the XON, CTS, DTR etc. it’s mostly not used but sometimes the other end still expects one of those.

i mostly do:
8 Bits, No parity, 1 Stop bit (9/10 times it’s these settings)
From the docs, first set these (perhaps in the constructor for your subclass?) and then connect after it.
Once one of these is changed after connection, you need to re-connect or they won’t be affected.

These are the settings that I am working with.
I was just not sure about setting flow control to none. I’m guessing that’s the XON, or is it the three top ones you listed?

They are all flow controls. CTS and DTR work together.
Perhaps it’s time to read the docs a little, they will give better understanding of the requirements.

I did read the docs. Since it isn’t working as I anticipated I started second guessing how I was interpreting them.

Am I right that the integer values stored in a memory block and converted to string should just be the bytes right? there would be no other manipulation of them?

Yep they wil just be bytes, no encodings or other things added. They call it a “a string is like a bucket of bytes” And so is a memoryblock.

An integer is 4-8 bits depending on the target system (32-bit system = 4 bits, 64-bit system is 8-bits) maybe this is unexpected in your code ?
The standard for most device-comm protcols is to pre-define it’s data bits/sizes.

This is all affirming. The vendor’s documentation specifies 8 bit integers too.
I’ll keep fishing.

Ah ha… the problem isn’t what I’m sending at all.
I connect and the serial connection immediately closes. Why might that happen?

Could be the baud rate? or maybe something else, try to check the Exception message?

this is it. there is no exception and I’m positive I have matched the vendor’s settings.
I just tried using the legacy serial object in Xojo… maybe it’s the same code, just renamed.

Please show some come that connects ?

Found it. I had assumed setting DTR to true was the same as setting Data Terminal Ready to True, but they are not.

1 Like