Skip to content

Instantly share code, notes, and snippets.

@MKo-xx
MKo-xx / 1.cs
Created December 25, 2010 09:40
get port list
using System.IO.Ports;
...
private void refresh_button_Click(object sender, EventArgs e)
{
portlist_comboBox.Items.Clear();
foreach (string s in SerialPort.GetPortNames())
{
portlist_comboBox.Items.Add(s);
}
}
@MKo-xx
MKo-xx / 2.cs
Created December 25, 2010 09:50
connect to serial port and send/receive data
private void connect_button_Click(object sender, EventArgs e)
{
...
string port_name = portlist_comboBox.SelectedItem.ToString(); // get serial port name
serial_port_ = new SerialPort(port_name, 9600); // set port name and speed 9600 bits/second
serial_port_.Open(); // connect to port
thread_ = new Thread(read_serial_port); // create thread for reading received data
thread_.Start();
...
@MKo-xx
MKo-xx / 3.cs
Created December 25, 2010 10:06
update text box from another thread
delegate void SetTextCallback(string newText);
private void add_output(string text)
{
if (this.output_textBox.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(add_output);
this.Invoke(d, new object[] { text });
}
else
{
@MKo-xx
MKo-xx / 1.pde
Created December 25, 2010 10:14
echo
void setup()
{
Serial.begin(9600);
}
void loop()
{
if (0 < Serial.available()) // See is there any coming data
{
char data = Serial.read(); // read first byte
Serial.println(data); // print data in HEX
@MKo-xx
MKo-xx / 1.pde
Created February 14, 2011 14:08
ADXL335
const int xpin = 0;
const int ypin = 1;
const int zpin = 2;
void setup()
{
Serial.begin(9600);
}
void loop()
@MKo-xx
MKo-xx / 1.cs
Created February 14, 2011 14:26
ADXL335 C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
@MKo-xx
MKo-xx / 1.pde
Created February 15, 2011 11:44
EEPROM
#include <EEPROM.h> // include library
int sz; // size of received data
void setup()
{
Serial.begin(9600);
sz = 0;
}
void loop()
@MKo-xx
MKo-xx / 1.c
Created February 27, 2011 10:22
Bluetooth scanner
// Compile using "gcc -o scanner 1.c -lbluetooth" command
// System
#include <stdio.h>
#include <stdlib.h>
// Bluetooth
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
@MKo-xx
MKo-xx / hcidump.c
Created March 6, 2011 10:06
device name parsing bug
//1004-1010 lines of src/hcidump.c
case 'i':
if (strcasecmp(optarg, "none") && strcasecmp(optarg, "system"))
device = atoi(optarg + 3);
else
device = HCI_DEV_NONE;
break;
@MKo-xx
MKo-xx / output.strace.c
Created March 16, 2011 11:50
strace's output of hcidump program
...
write(1, "HCI sniffer - Bluetooth packet a"..., 49) = 49
socket(PF_BLUETOOTH, SOCK_RAW, 1) = 3
bind(3, {sa_family=AF_BLUETOOTH, sa_data="\0\0\0\0\0\0\377\377\377\377\0\0\0\0"}, 6) = 0
socket(PF_BLUETOOTH, SOCK_RAW, 1) = 4
ioctl(4, HCIGETDEVINFO, 0x7ffff76cc630) = 0
close(4) = 0
ioctl(3, HCISETRAW, 0) = 0
close(3) = 0
socket(PF_BLUETOOTH, SOCK_RAW, 1) = 3