Skip to main content

Simple module for receiving binary data from a serial port

Project description

Simple module for receiving binary data from a serial port in an asynchronous form. Useful for receiving data from an Arduino or a microcontroller without the need to use strings.

Description

This modules lets you specify the format of the binary data and the header to be received from a serial port. The module creates a dedicated thread to read de serial port and feed the numpy arrays passed as buffers in a circular forma, always keeping the same length.

Example

In the example folder there is a script that creates a virtual serial port (works only on linux) allowing you to run test-receiver.py which will print the received data buffer.

An exemple code for an arduino to send data to be read using this module would be the fallowing:

void loop() {
  uint16_t adc_signal = analogRead(sensorPin);
  long unsigned t_now = micros();

  uint16_t buffer_size = sizeof(uint16_t) + sizeof(long unsigned) + 2;
  byte buf[buffer_size];
  buf[0] = 0xFD;
  memcpy(buf + 1, (byte *)&t_now, sizeof(unsigned long));
  memcpy(buf + 1 + sizeof(unsigned long), (byte *)&adc_vdd, sizeof(uint16_t));
  buf[buffer_size - 1] = '\n';
  Serial.write(buf, buffer_size);
}

In this case the format for receiving would be ‘Lh’. All the possible formats are defined in the struct package page .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

binarySerialReceiver-1.2.tar.gz (3.1 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page