Problems opening serial comm

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
deniska
Posts: 71
Joined: Mon Oct 17, 2005 1:38 pm
Location: New York

Problems opening serial comm

Post by deniska »

Hi,

I am having problems opening file descriptor to the serial port
The code below, mostly ripped of the lua player, always returns with:
"failed create SIO handle"
The PSP remote connector & the headphones are plugged in - They seem to send stuff back thru lua's serial echo script w/o any problems...

Any suggestions would be greatly appreciated...

Code: Select all


#include <pspkernel.h>
#include <pspdebug.h>
#include <pspiofilemgr.h>
#include <pspusb.h>
#include <pspusbstor.h>
#include <psppower.h>
#include <unistd.h>
#include <sys/stat.h>

PSP_MODULE_INFO&#40;"Hello SIO", 0, 1, 1&#41;;
#define printf pspDebugScreenPrintf
#define SIO_IOCTL_SET_BAUD_RATE 1

/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41; &#123;
          sceKernelExitGame&#40;&#41;;
          return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41; &#123;
          int cbid;

          cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
          sceKernelRegisterExitCallback&#40;cbid&#41;;

          sceKernelSleepThreadCB&#40;&#41;;

          return 0;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41; &#123;
          int thid = 0;

          thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
          if&#40;thid >= 0&#41; &#123;
                    sceKernelStartThread&#40;thid, 0, 0&#41;;
          &#125;

          return thid;
&#125;


static SceUID sio_fd = -1;
int baudRate = 2400;
char data&#91;256&#93;;

int main&#40;&#41; &#123;
pspDebugScreenInit&#40;&#41;;
SetupCallbacks&#40;&#41;;
printf&#40;"Hello SIO\n"&#41;;

if &#40;sio_fd < 0&#41; sio_fd = sceIoOpen&#40;"sio&#58;", PSP_O_RDWR, 0777&#41;;
if &#40;sio_fd < 0&#41; &#123;
        printf&#40;"failed create SIO handle."&#41;;
        sceKernelSleepThread&#40;&#41;;
        return 0;
&#125;

printf&#40;"performing ioctl.\n"&#41;;
sceIoIoctl&#40;sio_fd, SIO_IOCTL_SET_BAUD_RATE, &baudRate, sizeof&#40;baudRate&#41;, NULL, 0&#41;;

while &#40;1&#41; &#123;
        int count = sceIoRead&#40;sio_fd, data, 256&#41;;
        if &#40;count > 0&#41; printf&#40;"&#91;%s&#93;\n",data&#41;;

&#125;

sceKernelSleepThread&#40;&#41;;
return 0;
&#125;
Post Reply