hello I am newby to irda sockets. I have a macbook pro that has a built-in Apple IR reciver. I am using visual studio 2013,
#include <af_irda.h>
#include <winsock2.h>
#incude <iostream>
using namespace std;
#pragma comment(lib,"ws2_32.lib")
int main()
{
WORD wVersion = MAKEWORD(2,2);
WSADATA wSaData;
if(WSAStartup(wVersion), &wSaData))
{
cout << "Failed to initialize winsock library!\n";
return 1;
}
int irSock = socket(AF_IRDA, SOCK_STREAM, 0);
if(irSock == SOCKET_ERROR)
{
cout << "Socket creation failed! error code: " << WSAGetLastError() << endl;
}
//the socket creation failed with 10047
cout << endl << endl << endl;
system("pause");
return 0;
}
does this mean that my laptop doesn't have irda adapter?? if so what is IR receiver then?? can't we use IR receiver to write irda socket applications???
*** please anyhelp is highly appreciated
1- socket creation failed and WSAGetLastError() returns 10047 when the address family is not supported. (ie: the error doesn't belong to hardware but to platform)
on windows7, 8, 10 (almost all new windows OSs exclude irDA support) we get this error while on windows xp, linux fedora the socket creation succeeds BUT this doesn't mean that your laptop/pc is necessarily provided with irDA adapter.
2- IR receiver is not an irDA adapter:
An IR receiver is just a dumb receiver that reads IR commands (that was a tough one!). IRDA is a complex bidirectional protocol involving reliable communication with acknowledgments typically used to transfer files or emulate a serial interface between hand held devices and a laptop or PC. Or, as Wannabe said, you want an IR receiver since IRDA doesn't know how to listen to remote commands.
Related
I am writing a C program with the aim of configuring a peripheral device (the CS5368 ADC) via the I2C interface of a Dante Brooklyn II, a board based on a Microblaze soft-core processor running uClinux 2.4.
I have implemented the configuration following the Dante OEM docs for guidance, however when running my program I am encountering an "Operation not permitted" (EPERM) error when attempting to write data to I2C using i2c_smbus_write_byte_data.
Here is the section of code containing the culprit call to i2c_smbus_write_byte_data:
// Set ADC I2S to "Slave mode all speeds".
printf("Set the CS5368 I2S mode to slave\n");
unsigned char adc_dif = 0x01; // I2S mode
unsigned char adc_mode = 0x03; // Slave mode all speeds
unsigned char data = 0x90 | (adc_dif << 2) | adc_mode;
result = i2c_smbus_write_byte_data(i2c_fd, CS5368_GCTL_MDE, data);
if (result < 0) {
perror("Failed to write to the 'Global Mode Control' register");
return -1;
}
Here is the code within context of the full source of the small program. The program begins by resetting the CS5368 via a GPIO pin before doing the configuration via I2C.
EPERM is returned whether or not I have the CS5368 wired up. I've been able to successfully configure the CS5368 using the I2C interface of an Arduino Uno, so the issue does not appear to be related to the CS5368.
To run the program I login to the board via telnet as root, so I doubt the error has anything to do with user permissions.
The OEM docs state:
The Brooklyn II module can operate as an I2C controller running at
100Khz and using 7 bit addressing mode. It supports multi-master
operation. I2C devices can be accessed from user application running
on the Brooklyn II module. The interface supports the SMBus (System
Management Bus) protocol, which is a subset from the I2C protocol.
It goes on to list the supported i2c_smbus_* functions including i2c_smbus_write_byte_data, so the issue does not appear to be related to lack of support for SMBus or I2C.
I came across a related issue where a user was getting an EPERM error code when attempting to use the I2C write API, however the solution appears to have been to use the i2c_smbus_* API instead which I am already doing.
Any advice on what could be causing this error code to be returned or how to debug the issue further would be greatly appreciated!
Edit: In case it helps, here is the full output, starting from logging onto the board via telnet after having moved the exe to /tmp via ftp:
$ telnet 169.254.72.245
Trying 169.254.72.245...
Connected to 169.254.72.245.
Escape character is '^]'.
login: root
Password:
BusyBox v1.23.2 (2018-05-31 11:33:18 AEST) hush - the humble shell
/ # cd /tmp
/var/tmp # ./cs5368-i2c-config
Open GPIO device
Set GPIO tristate outputs
Set GPIO pins low
Sleep for 10 secs
Set GPIO pins high
Close GPIO file descriptor
Searching for I2C device
Opening /dev/i2c-0
Setting I2C_SLAVE 4c...
I2C Interface found: /dev/i2c-0
Set the CS5368 as the slave
Set the CS5368 I2S mode to slave
Failed to write to the 'Global Mode Control' register: Operation not permitted
I have a Qt5.12.4 MinGw64 app where I want to catch a USB event. In Windows 10 the MS driver for STM/USB emits error messages and I can use that as a trigger. Inelegant but it works, until I try to run it in a Win7-8.1 app where the driver is a third party STM driver with a VCP wrapper. I am thinking I need to adopt libusb to try and catch the ports change of state, but I am at a loss as how to proceed. I can see the port info in Device Manager, I just dont know how to get to it. Some of the questions going through my head....
1) Can I just make an OS call to read the port info? (if so, how?)
2) Can libusb and QSerialport co-exist on the same port?
3) What calls to LibUSB1.0 do I make to query the port status?
4) Is there a Windows cli utility like lsusb (wmic??) where I could scrape the data?
5) Which solution is likely to be the best cross platform solution?
I am using this trigger to start dfuse as a process that does a firmware update automatically on my STM board.
I have looked over the libusb1.0 docs but I do not understand just how I can use it. If that is correct solution, an example of how to query the Com port data and state would be most appreciated.
I tried using qDebug() to print out all of the serialportInfo data, while in serial or DFU state, but there is nothing there that is useful that I can use as a trigger.
USB serial mode = Serial port info is: ("COM3", "USB Serial Device", "Microsoft", "00000000001A", "\\.\COM3", "483", "5740", "1", " no data", "1")
USB DFU mode = Serial port info is: ("COM3", "N/A", "N/A", "N/A", "\\.\COM3", "N/A", "N/A", "no data", " no data", "no data")
I need some direction as to how to grab this port info so I dont really have any code that matters, but I am including an excerpt of my working process function.
This code works just fine to actually perform the firmware load. I just need a way to actually trigger it from a USB port change of state
void updateDevice_Dialog::update_firmware(QString fileName)
{
qDebug() << "Updating firmware: " << fileName ;
QDir dir;
ui->progress_label->setText("Preparing to update Firmware .....");
if(dir.setCurrent(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)+"/firmware"))
{
QSettings settings;
QString comPort = settings.value("USBPort").toString();
ui->progress_label->setText("Setting port to: "+comPort+" and starting download .....");
ui->avr_progressBar->setValue(0);
ui->avr_progressBar->setRange(0,100);
ui->avr_progressBar->setHidden(false);
progress_steps = 0; //reset avrProcess line output counter;
qDebug() << "Starting process for stm-dfu on serial port: " << comPort;
connect(avr_Process,SIGNAL(error(QProcess::ProcessError)),this,SLOT(process_error(QProcess::ProcessError)));
connect(avr_Process,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(process_finished(int,QProcess::ExitStatus)));
connect(avr_Process,SIGNAL(readyReadStandardOutput()),this,SLOT(process_readLine()));
connect(avr_Process,SIGNAL(errorOccurred(QProcess::ProcessError)),avr_Process,SLOT(kill()));
connect(avr_Process,SIGNAL(error(QProcess::ProcessError)),ui->avr_progressBar,SLOT(close()));
QString dfu_command = "\""+QCoreApplication::applicationDirPath()+"/Tools/\"dfusecommand -c -d --v --fn "
"\""+QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)+"/firmware/\""+fileName;
qDebug().noquote() << "dfu command string is: "<< dfu_command << " Current dir is: " << dir.currentPath();
avr_Process->start(dfu_command);
avr_Process->waitForFinished(20000);
}
}
From the perspective of the host system, rebooting the microcontroller into DFU will look like the original device was disconnected, and a completely different device was plugged in shortly afterwards.
If you need to watch for this, set up a libusb hotplug callback so that you'll be notified when the DFU device is attached.
I've installed (and have been using it for a while now) mongocxx driver via vcpkg and everything installed correctly and runs perfectly in Debug version (I'm using Visual Studio 2017 and my application is a Windows Form c++ (CLR) application). In my application, I get a connection pool and acquire a client everytime I upload some data on the server. Typical interval of my automatic data upload is 10 minutes.
My settings are
// Create pool (once)
mongocxx::uri uri_remote{ "mongodb://user:pwd#remote-host:PORT/database-name?minPoolSize=2&maxPoolSize=5" };
mongocxx::pool pool_remote{ uri_remote };
// The code below runs as a scheduled process after every 10 minutes
auto client_remote = pool_remote.acquire();
// The client is returned to the pool when it goes out of scope.
auto collection_remote = (*client_remote)["database-name"]["collection-1-name"];
auto collection_st_remote = (*client_remote)["database-name"]["collection-2-name"];
bsoncxx::document::value doc1= document
<< std::string(keys[0]) << entries[0] // A short string (device identifier)
<< std::string(keys[1]) << entries[1] // A short string location
<< std::string(keys[2]) << bsoncxx::types::b_date(std::chrono::system_clock::now()) // Current insert time
<< std::string(keys[3]) << entries[2] // String: updated entry name
<< std::string(keys[4]) << entries[3] // String: Updated entry description
<< std::string(keys[5]) << <float number>
<< std::string(keys[6]) << <integer>
<< finalize;
// Below are the statuses I'm recording. A binary array (length = 7)
bsoncxx::document::value doc2= document
<< std::string(status_keys[0]) << statuses[0]
<< std::string(status_keys[1]) << statuses[1]
<< std::string(status_keys[2]) << statuses[2]
<< std::string(status_keys[3]) << statuses[3]
<< std::string(status_keys[4]) << bsoncxx::types::b_date(std::chrono::system_clock::now())
<< std::string(status_keys[5]) << statuses[4] // Device identifier
<< std::string(status_keys[6]) << statuses[5]
<< finalize;
// And finally insert
try {
// Insert remote. lines of code for doc1 and doc2 are skipped
collection_remote.insert_one(doc1.view());
collection_st_remote.insert_one(doc2.view());
// I'm skipping the rest of the code section here (just a catch statement after this). . .
The problem, the database documents get uploaded every 10 minutes without a problem in Debug version, but with the Release version (when I loaded the Release version of my application and started using that), the mongo insert doesn't work every time 10 minutes. It just misses/skips some entries (mostly one after a successful attempt according to what I observed).
With the release version loaded in a remote computer I'm unable to do any debugging even though I ran debug version which works perfectly with shorter intervals too (like 1 minute each).
How do I enable ADC_1 interrupt in NVIC without using any library, in STM32F103RB microcontroller?
I am using keil uvision4.
The hardcore version:
*((volatile uint32_t *)((0xE000E000UL) + 0x0100UL)) = (uint32_t)(1UL << (((uint32_t)(int32_t)18) & 0x1FUL));
I'm trying to prepare for my master project in my last year by getting my head around mqtt. I've successfully installed mosquitto on my RPi, ran the test publish and subscribe (hello/world). I also managed to connect to the broker using the android app myMQTT and everything seams to run just fine. The problems start when i try to connect to the broker with an arduino with ethernet shield using the PubSubClient library by knolleary. Everything is connected to one switch (router-Rpi-arduino). I've made sure that the arduino has an unique ip-address an mac-address (I checked it in the router). The server ip-address is also correct as i'm using it to ssh into the Rpi.. The code running on the arduino keeps returning:
Attempting MQTT connection...failed, rc=-4 try again in 5 seconds
The returncode means connection timeout..
I'm running a fresh installed mosquitto on the pi so there's no username or password required to connect to the broker. Does anyone knows what i'm doing wrong here? I've been looking over the internet for a while now and i can't seem to figure it out.
Code running on the arduino:
/*
Basic MQTT example
This sketch demonstrates the basic capabilities of the library.
It connects to an MQTT server then:
- publishes "hello world" to the topic "outTopic"
- subscribes to the topic "inTopic", printing out any messages
it receives. NB - it assumes the received payloads are strings not binary
It will reconnect to the server if the connection is lost using a blocking
reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to
achieve the same result without blocking the main loop.
*/
#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>
// Update these with values suitable for your network.
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xAA };
IPAddress ip(192, 168, 1, 41);
IPAddress server(192, 168, 1, 26);
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i=0;i<length;i++) {
Serial.print((char)payload[i]);
}
Serial.println();
}
EthernetClient ethClient;
PubSubClient client(ethClient);
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (client.connect("arduinoClient")) {
Serial.println("connected");
// Once connected, publish an announcement...
//client.publish("outTopic","hello world");
// ... and resubscribe
client.subscribe("hello/world");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void setup()
{
Serial.begin(57600);
client.setServer(server, 1883);
client.setCallback(callback);
Ethernet.begin(mac, ip);
// Allow the hardware to sort itself out
delay(3000);
}
void loop()
{
if (!client.connected()) {
reconnect();
}
client.loop();
}
From the docs for the PubSubClient, the rc=-4 means the connection attempt has timed out. It has established a TCP connection, but the server has not responded to the MQTT connection attempt.
What version of mosquitto are you using? It is possible you are using an older version that doesn't support MQTT 3.1.1 that the PubSubClient defaults to now. If that is the case, you can change the MQTT_VERSION value in PubSubClient.h to revert back to MQTT 3.1.