[Solved] Help with sending Hex to serial port
Posted
#1
(In Topic #588)
Enthusiast

I have managed to get a small App to talk to a LCD Display and show "Hello World!" with no program and recently the LCD manufacturer
has sent over a list of commands that the screen supports.
I am hoping to send to the screen the Clear command (this is HEX 0C) how would I sent this to the screen?
I am using
Code
Write #SerialPort1, "Hello World!"So my question is how do I send the Hex command to the screen?
Posted
Regular

AndyGable said
I am hoping to send to the screen the Clear command (this is HEX 0C) how would I sent this to the screen?
So my question is how do I send the Hex command to the screen?
Since the hex value "0C" is and occupies one byte, you must specify it:
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Enthusiast

Select output mode = 1B 3D n (n= 0x30, 0x31, 0x32)
Select display mode = 1F n (n= 0x01, 0x02, 0x03)
Initialize the display = 1B 40
Move Cursor Up 1F 0A
Move to the Right most = 1F 0D
Bottom most position = 1F 42
Move to given location = 1F 24 X Y (1<= X, 1<= y <2)
Turn cursor on or off = 1F 43 n (n= 0,1)
Thanks for the advice so far on this project
Posted
Regular

Sorry, I didn't understand if you solved it.AndyGable said
Would that work for the following Commands
……
Thanks for the advice so far on this project
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Enthusiast

vuott said
Sorry, I didn't understand if you solved it.AndyGable said
Would that work for the following Commands
……
Thanks for the advice so far on this project
Sorry Vuott
I have the Clear command working but you said this was only a byte so do I send the command "1F 0D" (for example as it has more to it)
does it still work with the Write #SerialPort1, &h0C As Byte Code?
Posted
Regular

AndyGable said
but you said this was only a byte so do I send the command "1F 0D"
…obviously the problem is whether you have to send one byte at a time, or whether those two bytes represent a 16-bit value (in Gambas it is a "Short" data type).
In the first case you will have to repeat the "Write … As Byte " function twice (explicitly or with a loop), or you could use an array of type Byte[], as in the following example:
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Enthusiast

Code (gambas)
Posted
Regular

PJBlack said
Yes, perfect, if he prefers to use ASCII characters (as the character representation of a numeric value).
Theoretically, the substance does not change: they are always values that each occupy 8 bits (1 byte) of memory (in C is "char " datatype).
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Enthusiast

vuott said
Theoretically, the substance does not change: they are always values that each occupy 8 bits (1 byte) of memory.
yes …
Write #stream, bValue as byte
Write #stream, bValue as byte
Write #stream, bValue as byte
Write #stream, bValue as byte
Write #stream, bValue as byte
Write #stream, bValue as byte
is the same like
sString = bValue & bValue & bValue & bValue & bValue & bValue
write #stream, sString
but second one is much clearer (to me) and you con put it in a sub like
public sub outputserial (value as string)
write #stream,value
end
and wherre you need you can
outputserial(bValue & bValue & bValue & bValue & bValue & bValue)
outputserial(bdifferentValue)
1 guest and 0 members have just viewed this.



