전 C에서 프로그램을 쓰고 있어요 그리고 난 나에게 감사는 COM 포트
Q
는 COM 포트
-1
A
답변
1
나는 당신이 무엇인지 잘 모르겠어요 도와주세요 내가 COM 포트 에서 수신 할 수있는 방법을 알고 있으며 에서 데이터를 읽고 싶어을에 들어 찾고, 그러나 이것은 유닉스에 도움이 자사의 수 : Linux의
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <bstring.h> /* bzero(), bcopy() */
#include <unistd.h> /* read(), write(), close() */
#include <errno.h>
#include <sys/signal.h>
int obtain_socket(int port);
void show_message(int sd);
void close_down(int sigtype);
#define PORT 2001 /* default port for server */
#define SIZE 512 /* max length of character string */
int ssockfd; /* socket for PORT; global for close_down() */
int main()
{
int sd, client_len;
struct sockaddr_in client;
signal(SIGINT, close_down); /* use close_down() to terminate */
printf("Listen starting on port %d\n", PORT);
ssockfd = obtain_socket(PORT);
while(1) {
client_len = sizeof(client);
if ((sd = accept(ssockfd, (struct sockaddr *) &client,
&client_len)) < 0) {
perror("accept connection failure");
exit(4);
}
show_message(sd);
close(sd);
}
return 0;
}
int obtain_socket(int port)
/* Perform the first four steps of creating a server:
create a socket, initialise the address data structure,
bind the address to the socket, and wait for connections.
*/
{
int sockfd;
struct sockaddr_in serv_addr;
/* open a TCP socket */
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("could not create a socket");
exit(1);
}
/* initialise socket address */
bzero((char *)&serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(port);
/* bind socket to address */
if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
perror("could not bind socket to address");
exit(2);
}
/* set socket to listen for incoming connections */
/* allow a queue of 5 */
if (listen(sockfd, 5) == -1) {
perror("listen error");
exit(3);
}
return sockfd;
}
void show_message(int sd)
/* Print the incoming text to stdout */
{
char buf[SIZE];
int no;
while ((no = read(sd, buf, SIZE)) > 0)
write(1, buf, no); /* write to stdout */
}
void close_down(int sigtype)
/* Close socket connection to PORT when ctrl-C is typed */
{
close(ssockfd);
printf("Listen terminated\n");
exit(0);
}
0
당신은 Serial Programming HOWTO 있습니다.
관련 문제
- 1. 안드로이드 블루투스 COM 포트
- 2. COM 포트 찾기
- 3. COM 포트 터미널 프로그램
- 4. COM 포트 속도 변경
- 5. 가상 PC와의 COM 포트 통신
- 6. 열기 및 닫기 com 포트
- 7. 이미 사용중인 COM 포트 모니터링
- 8. 는 COM DLL
- 9. COM 포트 - 장치 식별 방법 (.net/C#)
- 10. PC COM 포트 초록색 표시등이있는 장치와 통신합니다.
- 11. ASP.NET 2.0 및 COM 포트 통신
- 12. 직렬 포트 닫히지 않습니다. COM 포트를 해제하려고합니다.
- 13. Windows x64 용 직렬/Com 포트 모니터
- 14. 가상 PC와의 COM 포트 통신 (파트 2)
- 15. LabVIEW를 사용하여 COM 포트 열기 및 닫기
- 16. SMS를 사용하여 Bluetooth COM 포트 연결 지침
- 17. 블루투스 장치에서 Windows API로 COM 포트
- 18. C#에서 COM 포트 가용성 확인
- 19. C++ 소스 코드 구성 - COM 포트 초기화
- 20. 시리얼 포트 또는 USB 포트?
- 21. IO 완료 포트 : WSARecv()는 어떻게 작동합니까?
- 22. "COM Interop에 등록하십시오"는 실제로 무엇을합니까?
- 23. 프로그래밍 방식으로 Windows에서 COM 포트 제거 (API 설정)
- 24. C# COM 포트 통신 - USB와 직렬 어댑터 간의 오류
- 25. C# 구성 파일에 여러 COM 포트 및 설정 정의
- 26. COM 포트 읽기 - 시간 초과 후 스레드가 살아 있음
- 27. COM 포트 데이터를 USB 포트 (GPS 데이터 내보내기 용)로 라우팅하는 방법
- 28. iPhone. 컴 포트 통신
- 29. C의 시리얼 포트
- 30. 포트 풀을 사용하여 포트 스캐닝
COM 포트를 사용하는 것은 OS마다 다르므로 원하는 OS를 알려줘야합니다. –
OS 특정 * 및 * 환경 특정. 표준 C 라이브러리 만? 프레임 워크가 전혀 없습니까? –
임베디드 시스템 용으로 개발 중이지만 사용할 운영 체제는 언급하지 않았다는 내용에 유의하십시오. 리눅스? Windows? BSD? 아마도, 다른 것? –