Autor Thema: tcp/ip raw send and then receive  (Gelesen 2550 mal)

yoggi

  • Gast
tcp/ip raw send and then receive
« am: 12 August 2014, 14:02:53 »
Hi Fhem forum,

I am new to Fhem and Perl scripting and I hope that I could get some help with my scripting problem.

I am trying to write a script to control my Sharp AQUOS TV over tcp/ip, I have found and partial modify existing Fhem script to work (71_DENON_AVR.pm and 70_ONKYO_AVR.pm). The problem I am having is that the TV only replies with 0, 1, OK, ERR etc. but with no prefix information which command was sent to the TV in the first place. Therefore I can't use the approach I have found in other scripts (e.g. if 'POWR?' power on is sent the reply would be something like 'POWR1' or 'POWR0' and were multiple request are sent at the same time.

What I need to do is to send e.g. 'POWR?   ' and wait for the TV to reply '0' or '1' before I can ask anything else.

I would like to use the built in 'DevIo.pm' if possible (since it is built in).

What I am hoping that somebody would provide is a short example that creates a socket send a command and then directly waits for a reply (before a new command can be sent). I also plan to keep the socket open (by calling the TV before it closes the connection. TV disconnects after 3 minutes if no activity is present) and reuse it.

TV commands are sent to the TV with carrier return at the end (\r) and replies from TV also have carrier return at the end.

Joachim
Sweden

Offline klausw

  • Developer
  • Hero Member
  • ****
  • Beiträge: 1895
Antw:tcp/ip raw send and then receive
« Antwort #1 am: 12 August 2014, 14:39:43 »
Hi Joachim,

have a look into the NetzerI2C module. It deals with RAW TCP and uses devio.

Regards
Klaus
RasPi B v2 mit FHEM 18B20 über 1Wire, LED PWM Treiber über I2C, Luchtdruck-, Feuchtesensor und ein paar Schalter/LED\'s zum testen
Module: RPI_GPIO, RPII2C, I2C_EEPROM, I2C_MCP23008, I2C_MCP23017, I2C_MCP342x, I2C_PCA9532, I2C_PCF8574, I2C_SHT21, I2C_BME280

Offline rudolfkoenig

  • Administrator
  • Hero Member
  • *****
  • Beiträge: 21258
Antw:tcp/ip raw send and then receive
« Antwort #2 am: 12 August 2014, 17:46:29 »
Zitat
What I am hoping that somebody would provide is a short example that creates a socket send a command and then directly waits for a reply (before a new command can be sent).

  my $client = IO::Socket::INET->new(PeerAddr => $addr); # $addr format: hostname:port
  syswrite($client, "a command");
  sysread($client, $answer, 256);

yoggi

  • Gast
Antw:tcp/ip raw send and then receive
« Antwort #3 am: 13 August 2014, 10:56:43 »
Thanks Klaus and Rudolf,

I will start to look at the example NetzerI2C.

Rodolf,

thanks for the example, but what I am looking for is a script that has a continues send and read function (maybe with the use of devio.pm) using while/loop or similar. All scripts I have looked at have been to simple (not the functions I am looking for) or to advanced for me to follow.


I have manage to us DevIO.pm to send and receive my commands.

I think that I need to save the outgoing command (e.g. 'POWR?   ') in order to track what the reply is for (since they are short and have no identifying prefix. Examples of answers are 'OK', '1' 'ERR' etc.).

Would the $hash list be a good place to save this information? Any advise how to prevent command and answer to get out of sync?

Any pointers would be appreciated!

Joachim
« Letzte Änderung: 13 August 2014, 17:14:33 von yoggi »

 

decade-submarginal