As a hobby i'm interesting programming a Ethernet connected LED sign to scroll messages across a screen. But I'm having trouble making a UDP sender in VB .net (using 2008 currently)
Now the sign is nice enough to have a specs sheet on programming for it: http://support.favotech.com/protocol.specs.2.4.jetfile.pdf
But an example of a line to send to it (Page 3):
<0x01>Z30<0x02>AA<0x06><0x1B>0b<0x1C>1<0x1A>1This message will show up on the screen<0x04>
With codes such as <0x01> representing the hex character.
Now, to send this to the sign I need to use UDP, however the examples I have all encode the message as ascii before sending, like this one: ( from http://www.java2s.com/Code/VB/Network-Remote/UDPClientsendspacketstoandreceivespacketsfromaserver.htm )
Imports System.Threading
Imports System.Net.Sockets
Imports System.IO
Imports System.Net
Public Class MainClass
Shared Dim client As UdpClient
Shared Dim receivePoint As IPEndPoint
Public Shared Sub Main()
receivePoint = New IPEndPoint(New IPAddress(0), 0)
client = New UdpClient(8888)
Dim thread As Thread = New Thread(New ThreadStart(AddressOf WaitForPackets))
thread.Start()
Dim packet As String = "client"
Console.WriteLine("Sending packet containing: ")
' ' Note the following line below, would appear to be my problem. ' Dim data As Byte() = System.Text.Encoding.ASCII.GetBytes(packet) client.Send(data, data.Length, "localhost", 5000) Console.WriteLine("Packet sent")
End Sub
Shared Public Sub WaitForPackets()
While True
Dim data As Byte() = client.Receive(receivePoint)
Console.WriteLine("Packet received:" & _
vbCrLf & "Length: " & data.Length & vbCrLf & _
System.Text.Encoding.ASCII.GetString(data))
End While
End Sub ' WaitForPackets
End Class
To output a hexcode in VB.net, I think the syntax may possibly be: &H1A , To send what the specs would define as <0x1A>
So my question is - could I modify that code, to correctly send a correctly formated packet to this sign?
edit The answers from Grant (After sending a packet with Hex in it), Hamish Smith (using a function to get hex values), and Hafthor ( hardcoded chr() message into example) When attempted all did not work, So I'll research to see what else could go wrong. In theory, if this string is sent successfully, I should have a message containing "OK" back, which will help to know when it works.
I have tried and am now able to monitor the packets going through. A working packet example is this (in raw hex): http://www.brettjamesonline.com/misc/forums/other/working.raw Vs my version: http://www.brettjamesonline.com/misc/forums/other/failed.raw . The difference is my hex codes are still not encoded correctly, seen in this side by side image: http://www.brettjamesonline.com/misc/forums/other/snapshotcoding.png . I have used this code to generate the packet and send it:
container = &H1 & "Z" & &H30 & &H2 & "temp.nrg" & &H1C & "1Something" & &H4
' This did not appear to work neither
'container = Chr(&H1) & "Z" & Chr(&H30) & Chr(&H2) & Chr(&H1C) & "1Something" & Chr(&H4)
'<0x01>Z00<0x02>FILENAME<0x1C>1Test to display<0x04> <- the "official" spec to send
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(container)
(full snippet: http://pastebin.com/f44417743 )