Not IRC related at all. It's hardware control over TCP/IP. Here's a example using the C code. There is an IPConnection object that handles all the TCP/IP stuff. Then there is a Temperature object that represents a temperature sensor. To interact with the temperature sensor the example creates an IPConnection object and a Temperature. The Temperature object will then use the IPConnection for its communication needs.

Getter Functions

Now to read the temperature of the sensor you just call temperature_get_temperature. This internally sends a request to the hardware asking for the current temperature. Then the sensor sends a response back containing the current temperature. During this message exchange the temperature_get_temperature blocks while waiting for a response. There is also a timeout mechanism. If the sensor doesn't respond within 2.5 sec then temperature_get_temperature will report an error.

#include <stdio.h> #include "ip_connection.h" #include "bricklet_temperature.h" #define HOST "localhost" #define PORT 4223 #define UID "XYZ" // Change to your UID int main() { // Create IP connection IPConnection ipcon; ipcon_create(&ipcon); // Create device object Temperature t; temperature_create(&t, UID, &ipcon); // Connect to brickd if(ipcon_connect(&ipcon, HOST, PORT) < 0) { fprintf(stderr, "Could not connect\n"); exit(1); } // Don't use device before ipcon is connected // Get current temperature (unit is °C/100) int16_t temperature; if(temperature_get_temperature(&t, &temperature) < 0) { fprintf(stderr, "Could not get value, probably timeout\n"); exit(1); } printf("Temperature: %f °C\n", temperature/100.0); printf("Press key to exit\n"); getchar(); ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally }

Just this getter mechanism alone would work without any threads, you only have to receive data during a getter call. If no getter is called no data will arrive from the hardware.

There seems to be a post size limit, so to be continued ...


In reply to Re^2: Socket client thread design problem by photron
in thread Socket client thread design problem by photron

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.