Updated: 2017 Sep 02
Thanks for all your comments. I have added more configurations according to your comments.
Dim StrIn as String= "String to calculate CRC" Dim CRCVal16 As UInt16 = 0 Dim crc As String CRCVal16 = CRC16_CCITT.Calculate(StrIn) crc = CRC16_CCITT.ToString(CRCVal16)
CRCVal16 = CRC16_CCITT.Calculate(Str1) CRCVal16 = CRC16_CCITT.Calculate(Str2, CRCVal16) crc = CRC16_CCITT.ToString(CRCVal16)
#define STRLEN 4 char str[STRLEN]={0x01,0x01,0x00,0x0B}; unsigned char c[2]; unsigned int crc; //Calculate CRC16 CCITT crc=CRC16CCITT_InitialValue(); crc=CRC16CCITT_Calculate(str,STRLEN,crc); CRC16CCITT_ToString(crc,c); printf("CRC16 CCITT = %02X %02X \n",c[0],c[1]);
#include<8052.h> void main() { int i; while(1) { P3_4=0; //Output 0 for(i=0;i<30000;i++); //delay loop P3_4=1; //Output 1 for(i=0;i<30000;i++); //delay loop } }
//File name: main.c #include "blink.h" void main() { while(1) { toggle(); delay(); } }
//File name: blink.c #include <8052.h> #include "blink.h" void toggle() { P3_4^=1; } void delay() { int i; for(i=0;i<30000;i++); //delay loop }
//File name: blink.h void toggle(); void delay();
'Author: Yan Naing Aye 'WebSite: http://cool-emerald.blogspot.sg/ 'Updated: 2009 April 24 '----------------------------------------------------------------------------- Public Class ClsMyStr Public Shared Function AsAsciiEncodedStr(ByVal CharString As String) As String Dim outS As String = "" Dim temp As String = "" Dim i As Integer = 0 For i = 0 To CharString.Length - 1 temp = "00" & Hex(Asc(CharString(i))) temp = Right(temp, 2) outS = outS & temp Next i Return outS End Function Public Shared Function AsSpacedAsciiEncodedStr(ByVal CharString As String) As String Dim outS As String = "" Dim temp As String = "" Dim i As Integer = 0 For i = 0 To CharString.Length - 1 temp = "00" & Hex(Asc(CharString(i))) temp = Right(temp, 2) outS = outS & temp & " " Next i Return outS End Function Public Shared Function AsAsciiDecodedStr(ByVal AsciiEncodedStr As String) As String Dim outS As String = "" Dim i As Integer = 0 Dim l As Integer = AsciiEncodedStr.Length - 2 If (AsciiEncodedStr.Length Mod 2) <> 0 Then l -= 1 End If For i = 0 To l Step 2 outS = outS & Chr(Val("&H" & AsciiEncodedStr.Substring(i, 2))) Next i Return outS End Function Public Shared Function GetAsciiEncodedStr(ByVal RawAsciiEncodedStr As String) As String Dim i As Integer = 0 Dim c As String Dim cmd As String = "" For i = 0 To RawAsciiEncodedStr.Length - 1 c = RawAsciiEncodedStr(i) If (Asc(c) >= &H30) AndAlso (Asc(c) <= &H39) Then cmd = cmd & c ElseIf (Asc(c) >= &H41) AndAlso (Asc(c) <= &H5A) Then cmd = cmd & c ElseIf (Asc(c) >= &H61) AndAlso (Asc(c) <= &H7A) Then cmd = cmd & Chr(Asc(c) - &H20) 'change to upper case Else 'MessageBox.Show("Got invalid character.") End If Next i If cmd.Length < 2 Then cmd = "0" & cmd End If Return cmd End Function Public Shared Function DoubleQuote() As String Return ControlChars.Quote End Function Public Shared Function Byte2Text(ByVal byteArray() As Byte) As String Dim str As String = BitConverter.ToString(byteArray) Return str End Function Public Shared Function Byte2Str(ByVal byteArray() As Byte) As String 'Dim str As String = System.Text.Encoding.ASCII.GetString(byteArray) Dim str As String = "" For i As Integer = 0 To UBound(byteArray) str &= Chr(byteArray(i)) Next Return str End Function Public Shared Function Str2Byte(ByVal str As String) As Byte() 'Dim ba() As Byte = System.Text.Encoding.ASCII.GetBytes(str) Dim ba() As Byte Try ReDim ba(str.Length - 1) For i As Integer = 0 To UBound(ba) ba(i) = Asc(str(i)) Next Catch ex As Exception ReDim ba(0) ba(0) = 0 End Try Return ba End Function Public Shared Function GetSignedDecimalText(ByVal RawStr As String) As String Dim i As Integer = 0 Dim c As String Dim cmd As String = "" For i = 0 To RawStr.Length - 1 c = RawStr(i) If (Asc(c) >= &H30) AndAlso (Asc(c) <= &H39) Then cmd = cmd & c ElseIf (Asc(c) = &H2D) Then If cmd.Length = 0 Then cmd = cmd & c End If Else 'MessageBox.Show("Got invalid character.") End If Next i Return cmd End Function End Class
Dim objStreamReader As StreamReader Dim strLine As String 'Pass the file path and the file name to the StreamReader constructor. objStreamReader = New StreamReader("C:\Boot.ini") 'Read the first line of text. strLine = objStreamReader.ReadLine 'Continue to read until you reach the end of the file. Do While Not strLine Is Nothing 'Write the line to the Console window. Console.WriteLine(strLine) 'Read the next line. strLine = objStreamReader.ReadLine Loop 'Close the file. objStreamReader.Close()
Dim objStreamWriter As StreamWriter 'Pass the file path and the file name to the StreamWriter constructor. objStreamWriter = New StreamWriter("C:\Testfile.txt") 'Write a line of text. objStreamWriter.WriteLine("Hello World") 'Write a second line of text. objStreamWriter.WriteLine("From the StreamWriter class") 'Close the file. objStreamWriter.Close()
Dim strLine As String Dim sr As StreamReader = Nothing Try sr = New StreamReader(fileName) strLine = sr.ReadToEnd() Finally sr.Close() End Try
Dim strLine As String Using sr As New StreamReader(fileName) strLine = sr.ReadToEnd End Using
'Author: Yan Naing Aye 'WebSite: http://cool-emerald.blogspot.sg/ 'Updated: 2009 June 25 '----------------------------------------------------------------------------- Imports System.IO Public Class ClsLog Private mEnableLog As Boolean = False Private mLogFileDirectory As String = "" Private mLogFilePath As String = "" Private mLogFileLifeSpan As Integer = 0 Private mLogFileFirstName As String = "AppName" Public Sub New() mEnableLog = False mLogFileDirectory = My.Application.Info.DirectoryPath mLogFileLifeSpan = 0 mLogFileFirstName = My.Application.Info.AssemblyName End Sub Public Property LogFileLifeSpan() As Integer Get Return mLogFileLifeSpan End Get Set(ByVal value As Integer) mLogFileLifeSpan = IIf(value >= 0, value, 0) End Set End Property Public Property LogFileFirstName() As String Get Return mLogFileFirstName End Get Set(ByVal value As String) mLogFileFirstName = value End Set End Property Public Property LogEnable() As Boolean Get Return mEnableLog End Get Set(ByVal value As Boolean) If value = True Then If Directory.Exists(Me.LogFileDirectory) Then mEnableLog = value Else mEnableLog = False Throw New Exception("Invalid file directory.") End If Else mEnableLog = value End If End Set End Property Public Property LogFileDirectory() As String Get Return mLogFileDirectory End Get Set(ByVal value As String) value = Trim(value) If Directory.Exists(value) Then Dim i As Integer = value.Length - 1 If (((value(i)) = "\") OrElse ((value(i)) = "/")) Then value = value.Substring(0, i) End If mLogFileDirectory = value Else Throw New Exception("Invalid file directory.") End If End Set End Property Public ReadOnly Property LogFilePath() As String Get Return mLogFileDirectory & "\" & mLogFileFirstName & Format(Now, "-yyyy-MMM-dd") & ".log" End Get End Property Public Sub WriteLog(ByVal LogEntry As String) If mEnableLog = True Then mLogFilePath = mLogFileDirectory & "\" & mLogFileFirstName & Format(Now, "-yyyy-MMM-dd") & ".log" Dim objStreamWriter As StreamWriter = New StreamWriter(mLogFilePath, True) Try objStreamWriter.WriteLine(LogEntry) Catch ex As Exception Finally objStreamWriter.Close() End Try End If End Sub Public Sub WriteTimeAndLog(ByVal LogEntry As String) WriteLog(Now.ToLongTimeString & " " & LogEntry) End Sub Public Sub CleanupFiles() If mLogFileLifeSpan > 0 Then 'if life span is zero, there will be no cleaning up Try Dim LogFiles() As String = Directory.GetFiles(mLogFileDirectory) For Each LogFile As String In LogFiles If (DateDiff("d", File.GetLastWriteTime(LogFile), Now) > mLogFileLifeSpan) _ AndAlso (Right(LogFile, 4) = ".log") Then File.Delete(LogFile) End If Next Catch ex As Exception End Try End If End Sub End Class
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing If MessageBox.Show("Do you really want to exit?", "Exit", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.No Then e.Cancel = True Me.Visible = False NotifyIcon1.Visible = True End If End Sub
Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick Me.Visible = True ' Show the form. Me.Activate() ' Activate the form. NotifyIcon1.Visible = False End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click ' Close the form, which closes the application. Me.Close() End Sub
Private Sub ContextMenuStrip1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ContextMenuStrip1.Click Me.Close() End Sub
<html>
<head>
<title>Key Capture</title>
<script src='keyCapture.js'></script>
</head>
<body>
<form>
Press a key to send to server.
<div id='text1' style="font-size: 40px; color:blue;">
</div>
</form>
</body>
</html>
var xmlHttp; document.onkeypress = DisplayMsg; function DisplayMsg(key_event) { var keyChar; if (document.all) { keyChar = String.fromCharCode(event.keyCode); } else if (document.getElementById) { keyChar = String.fromCharCode(key_event.which); } else if (document.layers) { keyChar = String.fromCharCode(key_event.which); } xmlHttp = GetXmlHttpObject(); if (xmlHttp == null) { alert("Your Browser does not support AJAX!"); return; } var url = "keyCapture.php"; url = url + "?keyC=" + keyChar + "&sid=" + Math.random(); xmlHttp.onreadystatechange = stateChanged; xmlHttp.open("GET", url, true); xmlHttp.send(null); }
function stateChanged() { if (xmlHttp.readyState == 4) { document.getElementById('text1').innerHTML = xmlHttp.responseText; } } function GetXmlHttpObject() { var xmlHttp = null; try { // Firefox, Opera 8.0+, Safari xmlHttp = new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; }
function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; }
var xmlHttp xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; }
function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}
xmlHttp.onreadystatechange=stateChanged;
var url = "keyCapture.php";
url = url + "?keyC=" + keyChar + "&sid=" + Math.random();
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
<?php
//get the parameter from URL
$k=$_GET["keyC"];
echo "Received: " . $k;
?>
<html>
<head>
<script language="JavaScript" type = "text/javascript">
<!--
document.onkeypress = DisplayMsg;
function DisplayMsg(key_event)
{
if (document.all) //Checks for IE 4.0 or later
{
document.form1.text1.value = String.fromCharCode(event.keyCode);
}
else if (document.getElementById) //checks for Netscape 6 or later
{
document.form1.text1.value = String.fromCharCode(key_event.which);
}
else if (document.layers) //Checks for Netscape 4
{
document.form1.text1.value = String.fromCharCode(key_event.which);
}
document.form1.submit();
}
//-->
</script>
<title>Capture Key Pressed</title>
</head>
<body>
<div style="display:none">
<form name="form1" action="key.php" method=GET>
<input type = "text" name = "text1">
</form>
</div>
<div style="font-size: 40px; color:blue;">
<?php
echo "Received: ";
echo $_GET["text1"];
?>
</div>
</body>
</html>