TCP Communications - Newbie needs help =)
mkleynhans
Posts: 78
Hi there,
I am new to the community and have only recently completed my lvl 1 programming course. I am getting there slowly
but have stumbled across the possibility of communicating to equipment via IP and have been battling to get it to work.
I have read through the forums and tried various different solutions including modifying modules and other code on the
the forum but just cant seem to get it to work..
Basically I have an Onkyo TX-NR609 av receiver which is enabled to be network controlled via TCP port 60128. I have
statically setup the amp on 192.168.0.34 on the network.
Using Hercules (a TCP client software), I can send the following hex strings to switch the amp on and off;
On:
49534350000000100000000801000000213150575230310d0a
Off:
49534350000000100000000801000000213150575230300d0a
I currently have the following in my main source file;
DEFINE_DEVICE
dvOnkyo = 0:5:0
dvTP = 10001:1:0
DEFINE_CONSTANT
hostIpAddress = '192.168.0.34'
hostPort = 60128
DEFINE_VARIABLE
nOnkyoConnected = 0
DEFINE_EVENT
data_event[dvOnkyo]
{
online:
{
nOnkyoConnected = 1
}
offline:
{
nOnkyoConnected = 0
ip_client_open(dvOnkyo.port,hostIpAddress,hostPort,IP_TCP)
}
}
BUTTON_EVENT[dvTP,1] // power on
{
PUSH:
{
SEND_STRING dvOnkyo,"$49,$53,$43,$50,$00,$00,$00,$10,$00,$00,$00,$08,$01,$00,$00,$00,$21,$31,$50,$57,$52,$30,$31,$0d,$0a";
}
}
BUTTON_EVENT[dvTP,2] // power off
{
PUSH:
{
SEND_STRING dvOnkyo,"$49,$53,$43,$50,$00,$00,$00,$10,$00,$00,$00,$08,$01,$00,$00,$00,$21,$31,$50,$57,$52,$30,$30,$0d,$0a";
}
}
Monitoring the Netlinx internal diagnostics shows the following;
Line 1 (23:06:29):: CIpEvent::OnLine 10001:1:1
Line 2 (23:06:29):: SendString to socket-local port (5) invalid
Line 3 (23:06:29):: CIpEvent::OnError 0:5:1
// This is after pressing button 1
Line 4 (23:06:31):: SendString to socket-local port (5) invalid
Line 5 (23:06:31):: CIpEvent::OnError 0:5:1
//This is after pressing button 2
Can you guys see where I am going wrong? I have honestly tried looking everywhere
but just cannot figure it out and its driving me crazy !!
Thanks in advance,
Mike
I am new to the community and have only recently completed my lvl 1 programming course. I am getting there slowly
but have stumbled across the possibility of communicating to equipment via IP and have been battling to get it to work.
I have read through the forums and tried various different solutions including modifying modules and other code on the
the forum but just cant seem to get it to work..
Basically I have an Onkyo TX-NR609 av receiver which is enabled to be network controlled via TCP port 60128. I have
statically setup the amp on 192.168.0.34 on the network.
Using Hercules (a TCP client software), I can send the following hex strings to switch the amp on and off;
On:
49534350000000100000000801000000213150575230310d0a
Off:
49534350000000100000000801000000213150575230300d0a
I currently have the following in my main source file;
DEFINE_DEVICE
dvOnkyo = 0:5:0
dvTP = 10001:1:0
DEFINE_CONSTANT
hostIpAddress = '192.168.0.34'
hostPort = 60128
DEFINE_VARIABLE
nOnkyoConnected = 0
DEFINE_EVENT
data_event[dvOnkyo]
{
online:
{
nOnkyoConnected = 1
}
offline:
{
nOnkyoConnected = 0
ip_client_open(dvOnkyo.port,hostIpAddress,hostPort,IP_TCP)
}
}
BUTTON_EVENT[dvTP,1] // power on
{
PUSH:
{
SEND_STRING dvOnkyo,"$49,$53,$43,$50,$00,$00,$00,$10,$00,$00,$00,$08,$01,$00,$00,$00,$21,$31,$50,$57,$52,$30,$31,$0d,$0a";
}
}
BUTTON_EVENT[dvTP,2] // power off
{
PUSH:
{
SEND_STRING dvOnkyo,"$49,$53,$43,$50,$00,$00,$00,$10,$00,$00,$00,$08,$01,$00,$00,$00,$21,$31,$50,$57,$52,$30,$30,$0d,$0a";
}
}
Monitoring the Netlinx internal diagnostics shows the following;
Line 1 (23:06:29):: CIpEvent::OnLine 10001:1:1
Line 2 (23:06:29):: SendString to socket-local port (5) invalid
Line 3 (23:06:29):: CIpEvent::OnError 0:5:1
// This is after pressing button 1
Line 4 (23:06:31):: SendString to socket-local port (5) invalid
Line 5 (23:06:31):: CIpEvent::OnError 0:5:1
//This is after pressing button 2
Can you guys see where I am going wrong? I have honestly tried looking everywhere
but just cannot figure it out and its driving me crazy !!
Thanks in advance,
Mike
0
Comments
Its so frustrating having to guess but am hoping that lvl 2 will shed some light on the mystery's
Now to try and get feedback on volume : /
- -3: unable to open communication port
- -2: invalid value for protocol
- -1: invalid server port
- 2: general failure (out of memory)
- 4: unknown host
- 6: connection refused
- 7: connection timed out
- 8: unknown connection error
- 9: port already closed
- 10: binding error
- 11: listening error
- 14: local port already in use
- 15: UDP socket already listening
- 16: to many open sockets
- 17: local port not open
These are for both servers and clients so some will only apply to one of the other.If the connection needs to be open all the time, I either run a timeline or a mainline check if the flag is off ... and if it is, that's where I open the connection, with a timeout that will change that flag from the pending state to the not connected state if anything goes wrong. I can then play with the status of that flag depending on what error code comes back and respond accordingly. In my experience, a delay of 30 seconds or so is usually appropriate between failed attempts to let the port settle down.
If it's the type of connection that is only open for a single exchange, then closes automatically, I'll only open the connection when I have something to send. The rest works the same.
I am now trying to capture data back with some difficulty.
I have thrown this in to see what is being read by my 2100;
DATA_EVENT [dvOnkyo]{
string:
{
send_string 0, "'Onkyo Amp Says',data.text";
}
}
and its only showing the first four characters of the string (ISCP). The full string should look something
like;
ISCP{00}{00}{00}{10}{00}{00}{00}{13}{01}{00}{00}{00}!1NTM02:46/04:34{1A}{0D}{0A}
I read on one of the posts that the master stops receiving the incoming info if it reads 00, is this true?
The plan was to try and receive data on the 2100 and then parse out individual messages and eventually
use these for feedback on the TP..
Alternatively, you can create a string and examine the string in debug displaying as hex. Something like:
In all likelihood, you'll find that your string is arriving correctly and you can use whatever string manipulation functions you desire to parse it.
To answer your question directly: It is NOT true that the master stops receiving when it finds $00 in the string. It's just a display (human interface) issue.
The master will receive and process the 00 "null" but it won't print it (send_string 0). It you want to print it you'll need to convert to something that diagnostics can process. There's a few functions on the forum that basically do a find and replace and another that will convert hex to ascii for printing to diagnostics. HEXBUG or something.
It seems that the possibilities are endless.
So I have go this far and am still only receiving the ISCP part, not any of the middle section or the actual code
that I am looking for...
DATA_EVENT [dvOnkyo]{
string:
{
stack_var char cMsg[50]
SELECT
{
ACTIVE (find_string (data.text,'!1MVL',1)):
{
cString = data.text
cVolume = left_string (cString,5)
SEND_COMMAND dvtp, "'^TXT-100,0,',cVolume"
}
}
}
}
In the text box, I am seeing ICSP but nothing else.. Have tried a few different combinations in the cString length and mide, am going to
keep trying but it looks like I am only receiving the first four bytes. Any ideas where I am going wrong?
Cheers,
Mike
Sorry for all the silly questions and thanks for all the help guys!! Am well chuffed.