Question Using NetworkStream to communicate to an Access Panel

PrimeTK

New member
Joined
Jul 31, 2012
Messages
4
Programming Experience
1-3
Hey everyone!

I am looking to write a console application to communicate to a panel.

This is a new job from my employer, and is essentially a 'let's see if we can do this' sort of a project.

I have never played with a network stream (read/write) before and I was hoping to be able to get some help on the basics of it.

I have the panel connected though the network(ethernet) and have programmed an IP into it and a Port.
In theory when my .Write gets to the panel with a connection request the Panel should respond. This is where is gets stuck.
The .Read on the network stream always returns '0' for the length of the buffer.
I can post some code if it is required but it, quite frankly' is messy as can be. So I was just hoping to get some tips first.

Thanks in advance.
 
You will likely need to provide a bit more detail... How does the exchange occur, what do you send and what do you expect to receive? Is it TCP or UDP?
 
It is a TCP transaction. though a socket.
I should be sending '@#####!V2'
the #'s are the account number that is already programmed into the panel and !V2 is a request for a connection.
Coming back I should get +V
 
This should do it:

        Dim TCPClient As New TcpClient(ipaddress, port)
        Dim NetStream As NetworkStream = TCPClient.GetStream()

        Dim MessageBytes() As Byte = System.Text.Encoding.ASCII.GetBytes("@#####!V2")
        NetStream.Write(MessageBytes, 0, MessageBytes.Length)

        Dim ResponseBytes() As Byte = New Byte(1) {}
        Dim ResponseLength As Integer = NetStream.Read(ResponseBytes, 0, 2)

        If System.Text.Encoding.ASCII.GetString(ResponseBytes).Replace(vbNullChar, "") = "+V" Then
            MessageBox.Show("Panel Activation Successful!")
        End If


Right John... Napkin code... :)
 
Last edited:
This should do it:
You can't pass Nothing as buffer argument to Read method, it must be an array of size big enough to receive the requested bytes.
Byte array .ToString will only return you the type name, you have to use an Encoding to translate the bytes to string.
 
That is pretty much what I already had...It isn't failing which is always good. but the response that I get back is '00'.
Across a network stream, you can only send Bytes, correct?
I am attempting to output what I get back with this.

For a As Integer = 0 To receiveLength
Console.WriteLine(receiveBytes(a).ToString())
Next

Just to see what it is.
hmm
Well I appreciate the help so far. At least I know I wasn't completely wrong it my attempts.
 
Across a network stream, you can only send Bytes, correct?
Ultimately yes, but you can use tools to simplify converting various data to bytes. For example you can use a StreamWriter/StreamReader on the stream, which means you could simply do a .Write(string) or .WriteLine(string).
As for the strings, do you use the correct encoding? Do the commands need to be terminated with cr/lf ?
 
I guess the issue comes down to, I'm not exactly sure what the panel is expecting. I assumed bytes, because of the low level processing. I don't know if it is HEX maybe?
I am pretty new to trying to communicate to panels haha.
I am not sure about the cr/lf. again I assume No. The manual hasn't mentioned anything about it that I saw ...
 
Back
Top