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 details)

Uploaded Source

File details

Details for the file binarySerialReceiver-1.2.tar.gz.

File metadata

  • Download URL: binarySerialReceiver-1.2.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for binarySerialReceiver-1.2.tar.gz
Algorithm Hash digest
SHA256 634790a37d30917f34a51bb9c9e0eaeb534a22abd2cc46a430471edd1eabd6ad
MD5 325fad2d5a6352839aed2c7596a6bc61
BLAKE2b-256 12581b2f68ffdaf0cd39349b6fceb34fc3daee427831334d4214eff370b20bfd

See more details on using hashes here.

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