0
我有一個小型嵌入式設備(Beaglebone黑色)與I2C設備掛鉤/dev/i2c-2
。I2C與Linux上的C#/單聲道
現在我試圖從C#/單聲道該設備進行通信,這怎麼可能? 我已經看過一些C++代碼,但在該語言中我不是很強大,但它看起來像它可能只是將其作爲文件打開並寫入它?雖然我不知道這個代碼如何轉換爲C#。
//C++ sample of i2c communication...
int BMA180Accelerometer::writeI2CDeviceByte(char address, char value){
cout << "Starting BMA180 I2C sensor state write" << endl;
char namebuf[MAX_BUS];
snprintf(namebuf, sizeof(namebuf), "/dev/i2c-%d", I2CBus);
int file;
if ((file = open(namebuf, O_RDWR)) < 0){
cout << "Failed to open BMA180 Sensor on " << namebuf << " I2C Bus" << endl;
return(1);
}
if (ioctl(file, I2C_SLAVE, I2CAddress) < 0){
cout << "I2C_SLAVE address " << I2CAddress << " failed..." << endl;
return(2);
}
char buffer[2];
buffer[0] = address;
buffer[1] = value;
if (write(file, buffer, 2) != 2) {
cout << "Failure to write values to I2C Device address." << endl;
return(3);
}
close(file);
cout << "Finished BMA180 I2C sensor state write" << endl;
return 0;
}
該示例使用'ioctl's,這不是C#中最簡單的事情。我可能會寫一個薄包裝,然後p /調用它。否則,它看起來只是文件訪問。 – Mitch
你能舉個例子,還是一些指針?不知道我會怎麼做? –