ايران ويج

نسخه‌ی کامل: ارسال اطلاعات از ميکرو به c# بوسيله پورت سريال!
شما در حال مشاهده‌ی نسخه‌ی متنی این صفحه می‌باشید. مشاهده‌ی نسخه‌ی کامل با قالب بندی مناسب.
سلام دوستان
من ميخوام اطلاعاتمو بفرستم توي #c در حقيقت مثل 1 ترمينال ببينم اطلاعات رو ! چندين مقاله خوندم ده ها برنامه نمونرو باز کردم ولي متاسفانه نميتونم اطلاعات دريافتيو ببينم! پرت باز ميشه براحتي ! send از pc به ميکرو هم انجام ميشه ! ولي متاسفانه اصلا اطلاعاتي دريافت نميکنم و نميبينم! لازم به ذکره بگم به محض باز کردن نرم افزارهاي استاندارد ترمينال مثل real term و باز کردن پرت همچي به خوبي ارسال و دريافت ميشه ! ولي متاسفانه توي نرم افزار c# هيچي دريافت و نشان داده نميشه! فقط پرتم بخوبي شناسايي و باز ميشه!
اين کد ساده اي ميکروئه که با real term جواب ميده :
کد:
/*
* GccApplication7.c
*
* Created: 7/12/2014 4:13:29 AM
*  Author: arash
*/


#include <avr/io.h>


#define F_CPU 7372800// Clock Speed
#define BAUD 9600
#define MYUBRR (F_CPU/16/BAUD)-1


void USART_Init( unsigned int ubrr)
{

    /* Set baud rate */
    UBRRH = (unsigned char)(ubrr>>8);
    UBRRL = (unsigned char)ubrr;
    /* Enable receiver and transmitter */
    UCSRB = (1<<RXEN)|(1<<TXEN);
    /* Set frame format: 8data, 2stop bit */
    UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0);
}

void USART_Transmit( unsigned int data )
{[url][/url]
    /* Wait for empty transmit buffer */
    while ( !( UCSRA & (1<<UDRE)) );
    /* Put data into buffer, sends the data */
    UDR = data;
}


int main(void)
{
    USART_Init(MYUBRR );
    while(1){
     USART_Transmit('a');
    }
}
نرم افزار c# همراه با سورس برنامرو ميزارم ! کسي ميدونه مشکل من از کجاست ؟؟؟
چرا توي c# کلا خط rx خاموشه و چيزي نمياد با وجودي ارتباط با پرت برقرار ميشه ؟ باز ميشه و اطلاعات از c# به ميکرو سند ميشه ؟؟
مرسي
http://s5.picofile.com/file/8140205350/P...1.rar.html
کنسولIo port رو چک کن ببین فراخوانی شده باشه
یه نمونه کد میزار م مربوط به ارتباط سی شارپ با سیم900 هستش
حدالامکان از دستورات قابل فهم برای ارتباط با پورت موازی استفاده شده
در ضمن برای سهولت بیشتر شما یه برنامه vspe نصب کن که خروجیش رو ببینی
کد php:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;
using System.Data;
using System.IO;


namespace 
Sim900
{
    class 
Program
    
{
        static 
void Main(string[] args)
        {

            
int ab;
            
int mSpeed 1;
            
string msg;


            
//==================Config=====
            
Console.ForegroundColor ConsoleColor.Green;
            
Console.WriteLine("1-Please Inter GSM Port Number:");
            
int port1 Convert.ToInt16(Console.ReadLine());
            
Console.WriteLine("2-Please Inter System Port Number:");
            
int port2 Convert.ToInt16(Console.ReadLine());

            
Console.WriteLine("2-Please Inter your Phone number:");
            
Int32 number Convert.ToInt32(Console.ReadLine());
            
            
SerialPort gsm = new SerialPort("COM" port19600Parity.None8StopBits.One);
            
gsm.Open();
            
SerialPort system = new SerialPort("COM" port29600Parity.None8StopBits.One);
            
            
//=================
            
Console.Clear();

            if (
gsm.IsOpen == true)


                
//=============
                
while (true)
                {
                
saeed:
                    
Console.ForegroundColor ConsoleColor.Green;
                    
Console.WriteLine("======= { SMS SERVER SIM900 DESIGNED BY S.SETAREH}======");
                    
Console.ForegroundColor ConsoleColor.Magenta;
                    
Console.WriteLine("1- SMS MOD ");
                    
Console.WriteLine("2- Dail   ");
                    
Console.WriteLine("3- EXIT  ");
                    
Console.WriteLine("===================================");
                    
Console.WriteLine("Please choose the On Item:");
                    
Console.ForegroundColor ConsoleColor.Red;





                    
Convert.ToInt16(Console.ReadLine());

                    
////////--------------

                    
if (== 1)
                    {

                    
sms:
                        
Console.Clear();
                        
Console.ForegroundColor ConsoleColor.Green;
                        
Console.WriteLine("======== { SMS MOD}======");
                        
Console.ForegroundColor ConsoleColor.Yellow;
                        
Console.WriteLine("1- Send SMS ");
                        
Console.WriteLine("2- Read SMS  ");
                        
Console.WriteLine("3- Delet All SMS");
                        
Console.WriteLine("4- Balance ");
                        
Console.WriteLine("5- Auto Controling ");
                        
Console.WriteLine("6- Back ");


                        
Convert.ToInt16(Console.ReadLine());


                        
//////////////////////////////////////////////////////
                        
if (== 1)
                        {
                            
Console.ForegroundColor ConsoleColor.DarkMagenta;
                            
Console.WriteLine("Please write the massege");
                            
msg Convert.ToString(Console.ReadLine());
                            
gsm.Write("AT+CMGF=1" Environment.NewLine);
                            
System.Threading.Thread.Sleep(200);
                            
gsm.Write("AT+CMGS=" + (char)34 number + (char)34 Environment.NewLine);
                            
System.Threading.Thread.Sleep(200);
                            
gsm.Write(msg Char.ConvertFromUtf32(26) + char.ConvertFromUtf32(13));
                            
System.Threading.Thread.Sleep(200);
                            
System.Threading.Thread.Sleep(mSpeed);
                            
Console.WriteLine("Send Sucsess!");
                            
System.Threading.Thread.Sleep(500);
                            
Console.Clear();
                            goto 
sms;

                        }
                        
/////////////////////////////////////////////////////////

                        
if (== 2)
                        {
                            
Console.Clear();
                            
Console.ForegroundColor ConsoleColor.Gray;

                            
Console.WriteLine("INBOX :");
                            
Console.ForegroundColor ConsoleColor.Yellow;
                            
gsm.Write("AT+CMGL=" + (char)34 "ALL" + (char)34 Environment.NewLine);
                            
System.Threading.Thread.Sleep(1000);
                            
string t gsm.ReadExisting();
                            
Console.WriteLine(t);


                        }






                        if (
== 3)
                        {
                            
gsm.Write("AT+CMGD=0,4" ";" Environment.NewLine);
                            
Console.WriteLine("All SMS DELETED..!");
                            
System.Threading.Thread.Sleep(500);
                            
Console.Clear();
                            goto 
sms;

                        }







                        if (
== 4)
                        {
                            
Console.Clear();
                            
Console.WriteLine("Your Balance :");
                            
Console.ForegroundColor ConsoleColor.Yellow;
                            
gsm.Write("ATD*140*1#" ";" Environment.NewLine);
                            
System.Threading.Thread.Sleep(7000);
                            
string o gsm.ReadExisting();
                            
Console.WriteLine(o);


                        }






                        if (
== 5)
                        {
                            
Console.ForegroundColor ConsoleColor.Cyan;
                            
Console.Clear();
                            
Console.WriteLine("SYSTEM IS ONLINE...");
                            
Console.ForegroundColor ConsoleColor.Green;
                            
gsm.Write("AT+CMGD=0,4" ";" Environment.NewLine);

                        
control:
                            
string t gsm.ReadExisting();
                            
System.Threading.Thread.Sleep(200);

                            if (
t.Contains("CMTI"))
                            {
                                
Console.Write("On sms Recived ==> ");
                                
gsm.Write("AT+CMGR=1" Environment.NewLine);
                                
System.Threading.Thread.Sleep(500);
                                
string g gsm.ReadExisting();


                                if (
g.Contains("1-ON"))
                                {

                                    
system.WriteLine("1");
                                    
Console.WriteLine("Relay 1 Is On");
                                    
gsm.Write("AT+CMGD=0,4" ";" Environment.NewLine);
                                    
System.Threading.Thread.Sleep(200);
                                    
gsm.Write("AT+CMGF=1" Environment.NewLine);
                                    
System.Threading.Thread.Sleep(200);
                                    
gsm.Write("AT+CMGS=" + (char)34 number + (char)34 Environment.NewLine);
                                    
System.Threading.Thread.Sleep(200);
                                    
gsm.Write("Relay 1 Is On" Char.ConvertFromUtf32(26) + char.ConvertFromUtf32(13));

                                    goto 
control;

                                }


                                if (
g.Contains("1-OFF"))
                                {
                                    
system.WriteLine("2");
                                    
Console.WriteLine("Relay 1 Is off");
                                    
gsm.Write("AT+CMGD=0,4" ";" Environment.NewLine);
                                    
System.Threading.Thread.Sleep(200);
                                    
gsm.Write("AT+CMGF=1" Environment.NewLine);
                                    
System.Threading.Thread.Sleep(200);
                                    
gsm.Write("AT+CMGS=" + (char)34 number + (char)34 Environment.NewLine);
                                    
System.Threading.Thread.Sleep(200);
                                    
gsm.Write("Relay 1 Is off" Char.ConvertFromUtf32(26) + char.ConvertFromUtf32(13));
                                    goto 
control;

                                }

                                if (
g.Contains("2-ON"))
                                {
                                    
system.WriteLine("3");
                                    
Console.WriteLine("Relay 2 Is On");
                                    
gsm.Write("AT+CMGD=0,4" ";" Environment.NewLine);
                                    
System.Threading.Thread.Sleep(200);
                                    
gsm.Write("AT+CMGF=1" Environment.NewLine);
                                    
System.Threading.Thread.Sleep(200);
                                    
gsm.Write("AT+CMGS=" + (char)34 number + (char)34 Environment.NewLine);
                                    
System.Threading.Thread.Sleep(200);
                                    
gsm.Write("Relay 2 Is On" Char.ConvertFromUtf32(26) + char.ConvertFromUtf32(13));
                                    goto 
control;

                                }

                                if (
g.Contains("2-OFF"))
                                {
                                    
system.WriteLine("4");
                                    
Console.WriteLine("Relay 2 Is off");
                                    
gsm.Write("AT+CMGD=0,4" ";" Environment.NewLine);
                                    
System.Threading.Thread.Sleep(200);
                                    
gsm.Write("AT+CMGF=1" Environment.NewLine);
                                    
System.Threading.Thread.Sleep(200);
                                    
gsm.Write("AT+CMGS=" + (char)34 number + (char)34 Environment.NewLine);
                                    
System.Threading.Thread.Sleep(200);
                                    
gsm.Write("Relay 2 Is Off" Char.ConvertFromUtf32(26) + char.ConvertFromUtf32(13));
                                    goto 
control;

                                }
                                if (
g.Contains("3-ON"))
                                {
                                    
system.WriteLine("5");
                                    
Console.WriteLine("Relay 3 Is On");
                                    
gsm.Write("AT+CMGD=0,4" ";" Environment.NewLine);
                                    
System.Threading.Thread.Sleep(200);
                                    
gsm.Write("AT+CMGF=1" Environment.NewLine);
                                    
System.Threading.Thread.Sleep(200);
                                    
gsm.Write("AT+CMGS=" + (char)34 number + (char)34 Environment.NewLine);
                                    
System.Threading.Thread.Sleep(200);
                                    
gsm.Write("Relay 3 Is On" Char.ConvertFromUtf32(26) + char.ConvertFromUtf32(13));
                                    goto 
control;

                                }


                                if (
g.Contains("3-OFF"))
                                {
                                    
system.WriteLine("6");
                                    
Console.WriteLine("Relay 3 Is off");
                                    
gsm.Write("AT+CMGD=0,4" ";" Environment.NewLine);
                                    
System.Threading.Thread.Sleep(200);
                                    
gsm.Write("AT+CMGF=1" Environment.NewLine);
                                    
System.Threading.Thread.Sleep(200);
                                    
gsm.Write("AT+CMGS=" + (char)34 number + (char)34 Environment.NewLine);
                                    
System.Threading.Thread.Sleep(200);
                                    
gsm.Write("Relay 3 Is off" Char.ConvertFromUtf32(26) + char.ConvertFromUtf32(13));
                                    goto 
control;

                                }

                                
Console.WriteLine("Cod is Error");
                                
gsm.Write("AT+CMGD=0,4" ";" Environment.NewLine);
                                
System.Threading.Thread.Sleep(200);
                                
gsm.Write("AT+CMGF=1" Environment.NewLine);
                                
System.Threading.Thread.Sleep(200);
                                
gsm.Write("AT+CMGS=" + (char)34 number + (char)34 Environment.NewLine);
                                
System.Threading.Thread.Sleep(200);
                                
gsm.Write("YOUR COD IS ERROR!" Char.ConvertFromUtf32(26) + char.ConvertFromUtf32(13));
                                goto 
control;
                            }


                            goto 
control;

                        }





                        if (
== 6)
                        {
                            
Console.Clear();
                            goto 
saeed;
                        }



                    }

                    if (
== 2)
                    {

                        
gsm.Write("ATD" +number";" Environment.NewLine);
                        
Console.ForegroundColor ConsoleColor.Red;
                        
Console.WriteLine("Dialing to Manager...");
                        
Console.WriteLine("Press 1 Disconnect");
                        
int s Convert.ToInt16(Console.ReadLine());
                        if (
== 1)
                        {
                            
gsm.Write("ATH" Environment.NewLine);
                            
Console.Clear();
                            goto 
saeed;
                        }



                    }



                    if (
== 3)
                    {

                  
                        
gsm.Close();
                        
system.Close();
                        
Environment.Exit(0);

                       


                    }


                }
            
                }
        }

    }