您好,
我们的项目需求是在任何时候都可以读取字库文件和图标文件,当Socket通讯正常时,文件操作没有问题。但是当Socket通讯不正常时,文件操作就会失败,会返回值-2005,对应着错误代码列表查到了#define SL_API_ABORTED (-2005L),Socket通讯和文件读取没有在一个线程里面,也没有相关性。怎么会出现这种情况呢?请问这是什么导致的呢?
调用方法:
1、图标文件操作
BMPFileHandle = sl_FsOpen((unsigned char *)DeviceFileName, SL_FS_READ, &MasterToken);
RetVal = sl_FsRead( BMPFileHandle, Offset, bmp_data, 0x36);//读取文件头信息
2、字库文件操作
DeviceFileHandle = sl_FsOpen((unsigned char *)DeviceFileName, SL_FS_READ, &MasterToken);
RetVal = sl_FsRead( DeviceFileHandle, Offset, p, FONT_SIZE);
user4696099:
采用的处理器为CC3235S,编译环境为CCS9.2.0
user4696099:
您好,
我们的项目需求是在任何时候都可以读取字库文件和图标文件,当Socket通讯正常时,文件操作没有问题。但是当Socket通讯不正常时,文件操作就会失败,会返回值-2005,对应着错误代码列表查到了#define SL_API_ABORTED (-2005L),Socket通讯和文件读取没有在一个线程里面,也没有相关性。怎么会出现这种情况呢?请问这是什么导致的呢?
调用方法:
1、图标文件操作
BMPFileHandle = sl_FsOpen((unsigned char *)DeviceFileName, SL_FS_READ, &MasterToken);
RetVal = sl_FsRead( BMPFileHandle, Offset, bmp_data, 0x36);//读取文件头信息
2、字库文件操作
DeviceFileHandle = sl_FsOpen((unsigned char *)DeviceFileName, SL_FS_READ, &MasterToken);
RetVal = sl_FsRead( DeviceFileHandle, Offset, p, FONT_SIZE);
Kevin Qiu1:
回复 user4696099:
Socket通讯不正常是什么造成的,你有修改过哪里
user4696099:
回复 Kevin Qiu1:
和此前相比,添加了几个标志位,都是用于获取Socekt状态的,并没有在Socket里面运用这些标志位
Kevin Qiu1:
回复 user4696099:
你是在哪个例程下修改的,可以把具体代码贴出来吗?
user4696099:
回复 Kevin Qiu1:
您好,
是在network terminal例程下添加修改的
void *TCPClientSocketRecvThread(void *arg)
{uint8_t nb;uint16_t portNumber;ip_t ipAddress;int32_t sock_connect_status, sock_recv_status,sock_send_status;int32_t nonBlocking;SlSockAddr_t*sa;int32_t addrSize;sockAddr_t sAddr;ReportPacket_Typedef ReportPacketParams;Midware_Host_IPAddress=IPADRSTRING;Midware_Host_Port = PORTNUMBER;nb = FALSE;//FALSE;TRUEipAddress.ipv4 = Midware_Host_IPAddress;portNumber = Midware_Host_Port;
/* filling the TCP server socket address */sAddr.in4.sin_family = SL_AF_INET;
/* Since this is the client's side,* we must know beforehand the IP address* and the port of the server wer'e trying to connect.*/sAddr.in4.sin_port = sl_Htons((unsigned short)portNumber);sAddr.in4.sin_addr.s_addr = sl_Htonl((unsigned int)ipAddress.ipv4);
sa = (SlSockAddr_t*)&sAddr.in4;addrSize = sizeof(SlSockAddrIn6_t);
/* Get socket descriptor – this would be the* socket descriptor for the TCP session.*/TcpClientSock = sl_Socket(sa->sa_family, SL_SOCK_STREAM, TCP_PROTOCOL_FLAGS);ASSERT_ON_ERROR(TcpClientSock, SL_SOCKET_ERROR);#ifdef SECURE_SOCKET
SlDateTime_t dateTime;dateTime.tm_day = DEVICE_DATE;dateTime.tm_mon = DEVICE_MONTH;dateTime.tm_year = DEVICE_YEAR;
sl_DeviceSet(SL_DEVICE_GENERAL, SL_DEVICE_GENERAL_DATE_TIME,sizeof(SlDateTime_t), (uint8_t *)(&dateTime));
/* Set the following to enable Server Authentication */sl_SetSockOpt(TcpClientSock,SL_SOL_SOCKET,SL_SO_SECURE_FILES_CA_FILE_NAME,ROOT_CA_CERT_FILE, strlen(ROOT_CA_CERT_FILE));#ifdef CLIENT_AUTHENTICATION/* Set the following to pass Client Authentication */sl_SetSockOpt(TcpClientSock,SL_SOL_SOCKET,SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME,PRIVATE_KEY_FILE, strlen(PRIVATE_KEY_FILE));sl_SetSockOpt(TcpClientSock,SL_SOL_SOCKET,SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME,TRUSTED_CERT_CHAIN, strlen(TRUSTED_CERT_CHAIN));
#endif
#endif
/* Set socket as non-blocking socket (if needed):* Non-blocking sockets allows user to handle* other tasks rather than block* on socket API calls.* If an API call using the Non-blocking socket descriptor* returns 'SL_ERROR_BSD_EAGAIN' -* this indicate that the user should try the API again later.*/
if(TRUE == nb){nonBlocking = TRUE;sock_connect_status = sl_SetSockOpt(TcpClientSock, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlocking,sizeof(nonBlocking));
if(sock_connect_status < 0){sl_Close(TcpClientSock);return(-1);}}
sock_connect_status = -1;while(1){if (sock_connect_status >= 0){tcpflag = 1;memset(TCPClientRecvBuffer, 0, sizeof(TCPClientRecvBuffer));sock_recv_status = sl_Recv(TcpClientSock, TCPClientRecvBuffer, MAX_BUF_SIZE, 0);usleep(3);if((sock_recv_status == SL_ERROR_BSD_EAGAIN) && (TRUE == nb)){tcpflag = 0;sleep(1);continue;}else if(sock_recv_status < 0){LCDSOCK_RECV_STATUS = sock_recv_status;tcpflag = 0;sl_Close(TcpClientSock);TcpClientSock = -1;}
else if(sock_recv_status == 0){tcpflag = 0;LCDSOCK_RECV_STATUS = sock_recv_status;sl_Close(TcpClientSock);TcpClientSock = -1;sock_connect_status = -2;}else{MidwareHostcmdProcCallback(TCPClientRecvBuffer);tcpflag = 1;}}usleep(3);if (sock_connect_status < 0){if (TcpClientSock < 0){TcpClientSock = sl_Socket(sa->sa_family, SL_SOCK_STREAM, TCP_PROTOCOL_FLAGS);ASSERT_ON_ERROR(TcpClientSock, SL_SOCKET_ERROR);}
/* Calling 'sl_Connect' followed by server's* 'sl_Accept' would start session with* the TCP server. */
sock_connect_status = sl_Connect(TcpClientSock, sa, addrSize);LCDSOCK_CONNECT_STATUS = sock_connect_status;
if((sock_connect_status == SL_ERROR_BSD_EALREADY)&& (TRUE == nb)){tcpflag = 0;sleep(1);}else if(sock_connect_status == 0){
LCDSOCK_CONNECT_STATUS = sock_connect_status;}else if(sock_connect_status < 0){LCDSOCK_CONNECT_STATUS = sock_connect_status;tcpflag = 0;sl_Close(TcpClientSock);TcpClientSock =-1;}usleep(300);}}
Kevin Qiu1:
回复 user4696099:
从这个看不出什么,你把文件读写部分的也贴出来