Opening the USB ports in C++
Imported from the Apple Support Forums via the Wayback Machine 🔗
Hi All,
I need to open a USB port to send an encrypted text file to it. In Uni we have been doing this but instead of the USB ports we have been using the COM1 port. However I don't have a COM port on my mac so I wanted to use the USB port and a flash disk.
Here is my code at the moment:
#include <iostream>
#include <stdio.h>
#include <curses.h>
int main (int argc, char * const argv[]) { // Start of the program
#define CNTRLZ 0x9A
FILE * fp;
FILE * dp;
char FileOpenSTR[] ="\TEMPtext.txt";
char WriteAccess [] = "w";
char ReadAccess [] = "r";
char COM1 [] = "COM1";
//char USB []="";
//char FireWire[]="";
int c;
if ((fp = fopen(FileOpenSTR, ReadAccess)) == NULL) {
printf("fail to open data filen"); return 1;
}
if ((dp = fopen(COM1, WriteAccess)) == NULL) {
printf("fail to open COM portn"); return 1;
}
while ((c = fgetc(fp )) != EOF) {
fputc( c, dp);
}
fputc(CNTRLZ, dp);
fflush(dp);
fclose(fp);
return 0; // End of the program
}
The above code is to open the COM port and I'm not sure what I have to change to open the USB or FireWire ports.
Anyone help here?
Thanks,
Greg
1 reply
Sign in or join Beachball Help to reply.
- 0