㈠ c語言同步和非同步的區別
同步:代碼立即執行
非同步:代碼程序先在隊列排隊,等到可以執行再去執行。
㈡ C語言問題
你這個程序是捕捉0到9的按鍵狀態,按下再松開時才會記錄,想要識別所有按鍵,把for循環范圍擴大。
比如for(charch=32;ch<=127;ch++)這樣就包含了特殊符號及大小寫字母還有數字。
但是,這個代碼是有問題的!
一、你這個代碼需在鍵位已經按下後啟動才能識別,否則啟動時沒有按下對應鍵位,程序就結束了。要嵌套死循環,讓其一直檢測。
二、直接擴大ASCII區間,像上面的那樣32~127,識別字母區間會被防毒軟體直接判斷為病毒!!。
三、GetAsyncKeyState不是C語言庫函數,是window的函數,換其它操作系統就失效。
GetAsyncKeyState返回值最高位為1則說明對應ch的鍵被按下,所以這里用&0x8000來判斷最高位。
四、想要捕獲其它軟體界面內容還有很多方法,比如:
1、通過windowAPI函數FindWindow來獲取窗口句柄。
2、遍歷窗口下控制項句柄,找到輸入框句柄。
3、通過窗口句柄找到進程id(GetWindowThreadProcessId函數),再通過id獲取進程句柄(OpenProcess函數)。
4、向目標進程申請內存(VirtualAllocEx),再通過PostMessage函數非同步發送消息獲取目標控制項內的內容(具體消息要結合控制項類型,另外注意PostMessage是非同步執行)。
具體自行查閱資料,一言兩語說不清,上面步驟需先搞懂window消息機制。
注意:以上方法依然只限window系統,且有數據保護的控制項無法獲取。
五、或簡單暴力的方法,直接寫個定時截圖,只要硬碟夠不停桌面截圖。
但不論寫什麼程序,和裝攝像頭一樣,終究都會被發現。!!!!!!!!!!!!!
㈢ C語言 Asynchronous_send 我用 Asynchronous_send(j/100);
j/100=0
這大概不是沒有輸出,而是輸出一個不可見字元,而你根據列印結果看是否有輸出,當然不正確
至於'j/100'只輸出一個j,記住這個函數是非同步發送,你恐怕還得等好久才能收完,接收方要不斷接收才能得到結果
㈣ c51單片機 C語言問3和4道題
非同步串列通信是指通信雙方以一個字元(包括特定附加位)作為數據傳格單位且發送方傳送字元的間隔時間不一定。同步串列通信是指允許連續發送一序列字元而每個字元的數據位數都相同且沒有起始位和停止位。 非同步串列通信是指通信中兩個位元組間的時間間隔是不固定的,而在同一個位元組中的兩個相鄰位的時間間隔是固定的.。同步串列通信則是在通信過程中每個位元組的時間間隔是相等的,而且每個位元組的位的時間間隔也是固定的。非同步通信數據幀的第一位是開始位,在通信線上沒有數據傳送時處於邏輯「1」狀態。當發送設備要發送一個字元數據時,首先發出一個邏輯「0」信號,這個邏輯低電平就是起始位。起始位通過通信線傳向接收設備,當接收設備檢測到這個邏輯低電平後,就開始准備接收數據位信號。
㈤ c語言中UART是什麼意識
Universal Asynchronous Receiver/Transmitter,通用非同步接收/發送裝置
一般就是串口了,比如單片機,PC都有的串口。
㈥ PIC單片機16F883 串列非同步通信 c語言編程 請詳細寫出各個寄存器,串口的作用,謝謝了。
#include <pic.h>
#define FOSC 18432000L
#define BAUD 115200
#define NONE_PARITY 0 //無校驗位
#define ODD_PARITY 1 //奇校驗
#define EVEN_PARITY 2 //偶校驗
#define MARK_PARITY 3 //標記校驗
#define SPACE_PARITY 4 //空校驗
#define PARITYBIT EVEN_PARITY
#define S2RI 0x01
#define S2TI 0x02
#define S2RB8 0x04
#define S2TB8 0x08
sfr AUXR = 0x8e;
sfr S2CON = 0x9a;
sfr S2BUF = 0x9b;
sfr BRT = 0x9c;
sfr IE2 = 0xaf;
bit busy;
void SendData(char dat);
void SendString(char *s);
void main()
{
#if (PARITYBIT == NONE_PARITY)
S2CON = 0x5a; //8位可變波特率 (無校驗位)
#elif (PARITYBIT == ODD_PARITY) || (PARITYBIT == EVEN_PARITY) || (PARITYBIT == MARK_PARITY)
S2CON = 0xda; //9位可變波特率,校驗位初始為1
#elif (PARITYBIT == SPACE_PARITY)
S2CON = 0xd5; //9位可變波特率,校驗位初始為0
#endif
BRT = -(FOSC/32/BAUD); //設置獨立波特率發生器的重載初值
AUXR = 0x14; //獨立波特率發生器工作在1T模式
IE2 = 0x01; //使能串口2中斷
EA = 1; //開總中斷
SendString("STC12C5A60S2\r\nUart2 Test !\r\n");
while(1);
}
void Uart2() interrupt 8 using 1
{
if (S2CON & S2RI)
{
S2CON &= ~S2RI; //清除接收完成標志
P0 = S2BUF; //P0顯示串口數據
P2 = (S2CON & S2RB8); //P2.2顯示校驗位
}
if (S2CON & S2TI)
{
S2CON &= ~S2TI; //清除發送完成標志
busy = 0;
}
}
void SendData(char dat)
{
while (busy); //等待上個數據發送完成
ACC = dat; //取得偶校驗位P
if (P) //根據P來設置串口數據的校驗位
{
#if (PARITYBIT == ODD_PARITY)
S2CON &= ~S2TB8; //置校驗位為0
#elif (PARITYBIT == EVEN_PARITY)
S2CON |= S2TB8; //置校驗位為1
#endif
}
else
{
#if (PARITYBIT == ODD_PARITY)
S2CON |= S2TB8; //置校驗位為1
#elif (PARITYBIT == EVEN_PARITY)
S2CON &= ~S2TB8; //置校驗位為0
#endif
}
busy = 1;
S2BUF = ACC; //發送數據
}
void SendString(char *s)
{
while (*s) //判斷字元串結束標志
{
SendData(*s++); //發送字元
}
}
㈦ 怎樣寫socket要求非同步通信的,能傳輸不大於1mb的文件,用C語言的版本
使用UDP
查看下linux關於socket的相關函數,給你寫個簡單的實例:
include.h:
#include<stdio.h>
#include<stdlib.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<string.h>
#include<netinet/in.h>
#include<netdb.h>
#include<sys/socket.h>
#include<errno.h>
接收代碼:
#include"include.h"
#define port 9999
#define LENGTH 1024
struct str
{
int type;
char buff[LENGTH];
};
void rcv(int sock)
{
struct sockaddr_in addr;
int length,n;
int running=1;
struct str frame;
char buffer[2000];
while(running)
{
bzero(&frame,sizeof(struct str));
length=sizeof(struct sockaddr);
n=recvfrom(sock,(struct str*)&frame,sizeof(struct str),0,(struct sockaddr *)&addr,&length);
//memcpy(&frame,buffer,sizeof(struct str));
printf("Server has recieved %s !\n",frame.buff);
puts(frame.buff);
printf("Server has recieved sending type %d !\n",frame.type);
}
}
int main(void)
{
int sock_fd;
struct sockaddr_in addr;
if((sock_fd=socket(AF_INET,SOCK_DGRAM,0))<0)
{
printf("Error in socket!\n");
exit(1);
}
bzero(&addr,sizeof(struct sockaddr_in));
addr.sin_family=AF_INET;
addr.sin_addr.s_addr=htonl(INADDR_ANY);
addr.sin_port=htons(port);
if(bind(sock_fd,(struct sockaddr *)&addr,sizeof(struct sockaddr_in))<0)
{
printf("Error in bind!\n");
exit(1);
}
rcv(sock_fd);
close(sock_fd);
}
發送代碼:
#include"include.h"
#define port 9999
#define LENGTH 1024
struct str
{
int type;
char buff[LENGTH];
};
void snd(int sock)
{
int n;
struct sockaddr_in addr;
struct str frame;
char ipaddr[15];
int running=1;
char content[1200];
while(running)
{
bzero(&frame,sizeof(struct str));
bzero(&addr,sizeof(struct sockaddr_in));
addr.sin_family=AF_INET;
addr.sin_port=htons(port);
printf("please input the ip address!\n");
gets(ipaddr);
if(inet_aton(ipaddr,&addr.sin_addr)<0)
{
printf("Ip error!\n");
exit(1);
}
frame.type=5;
printf("please input the content which you wanna send!\n");
fgets((&frame)->buff,LENGTH,stdin);
printf("aim ip is ");
puts(ipaddr);
printf("the content you wanna send is %s !\n",(&frame)->buff);
printf("type is %d!\n",frame.type);
n=sendto(sock,(struct str *)&frame,sizeof(struct str),0,(struct sockaddr *)&addr,sizeof(struct sockaddr_in));
if(n<0)
{
printf("fail in sendto()\n");
exit(1);
}
bzero(&frame,sizeof(struct str));
}
}
int main(void)
{
int sock_fd;
if((sock_fd=(socket(AF_INET,SOCK_DGRAM,0)))<0)
{
printf("Error in socket()!\n");
exit(1);
}
snd(sock_fd);
close(sock_fd);
}
㈧ 用c語言單片機發一個正弦波 為何不寫延時程序串口傳數就會出錯 延時程序: void delay(v
串口發送數據是非同步發送,而且是一位一位的發送。
非同步的意思是不需要同步時鍾,通訊雙方約定好時間,比如9600BPS,即每秒9600位數據,一位數據需要大約0.1毫秒。發送一個位元組是8位,再加上起始位、終止位,可能還有校驗位,大約在1毫秒左右。這就是說,9600BPS的通訊速率,每發送一個位元組(大約)需要1毫秒的時間。
通常發送的時候不需要刻意的延時,而是通過檢測標志狀態的方法確定發送是否完成。比如
SBUF=A;
while( !TI ); // 這個狀態檢測就起延時的作用。如果沒有這個發送完成的檢測,delay(2ms)也可以。
TI = 0;
㈨ 【C語言Playsound】非同步播放與同步播放
應無問題:
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
void main()
{
PlaySound (TEXT("zzd.wav"), NULL, SND_ASYNC | SND_NODEFAULT);
while (1)
{
printf("program is running... here\n");
Sleep(1000);
}
exit(0);
}
如果你的編譯器支持中文,你把.wav 或 .wma 之類的 音頻 文件名和 路徑 換成 你的 E:\\路徑\\文件名 便可。
㈩ 用C語言,向一個指定的的窗口發送固定的信息,怎麼實現啊 希望能提供源代碼參考。希望大家不吝賜教
先取得窗口的句柄,如果是前台窗口,可以用 GetForegroundwindow獲取!
如果知道窗口名等,也可以用FindWindow獲取窗口句柄!
然後用SendMessage發送消息即可