boss-tech's Blog
boss-tech's Blog

Moj blog

Dobrodošel gost ( Prijava | Registriraj se )

Java In Serial Port

Avtor boss-tech, 22 Jul 2009, 10:56

Kako komunicirati z napravami preko serijskega porta ter USBja?

Najprej sem mal googlal, vendar nič pametnega... najdem java comm od sun-a, pridem lepo do downloada knjižnice - stran ne obstaja. Potem pa le najdem en forum, kjer predlagajo knjižnico RXTX, ki jo najdeš na http://users.frii.com/jarvi/rxtx oz download na http://rxtx.qbang.org/wiki
Ko stvar preneseš, jo razpakiraš in dobiš knjižnice za win, linux, macos ter solaris + jar datoteka.

Jaz sem delal v win, tako da sem uporabil win dllje ter jar file. Prekopirat pa jih moraš v:

Installation of javax.comm on Linux

copy libLinuxSerialParallel.so to /usr/lib/
copy javax.comm.properties to [JDK-directory]/jre/lib/
copy comm.jar to [JDK-directory]/lib/

Installation of rxtxSerial (from www.rxtx.org) on Linux

copy librxtxSerial.so to /usr/lib
copy RXTXcomm.jar to [JDK-directory]/jre/lib/ext/

Installation of rxtxSerial (from www.rxtx.org) on Windows

copy rxtxSerial.dll to [JDK-directory]\jre\bin\rxtxSerial.dll
copy RXTXcomm.jar to [JDK-directory]\jre\lib\ext\RXTXcomm.jar

Ko imaš te knjižnice pa lahko začneš z delom. Jar file je potrebno še dodati v library v projektu v javi (jaz uporabljam eclipse). Potem pa lahko začnemo s kodo:

Main class

private void connect(String portName) throws Exception {

try {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
if (portIdentifier.isCurrentlyOwned()) {
System.out.println("Error: Port is currently in use");
} else {
CommPort commPort = portIdentifier.open(this.getClass().getName(),2000);

if (commPort instanceof SerialPort) {
SerialPort serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(115200, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);

System.out.println("Device connected...");

InputStream in = serialPort.getInputStream();
SerialReader reader = new SerialReader(in);
reader.run();

OutputStream out3 = serialPort.getOutputStream();
SerialWriter writer = new SerialWriter(out3, serialPort);

writer.setCommand("xxx");
writer.run();


//close comport
try{
commPort.close();

}
catch (Exception e) {
System.out.println("Close port error "+ e);
}
} else
System.out
.println("Error: Only serial ports are handled by this example.");
}

} catch (Exception conn) {
System.out.println("Error connecting:"+conn);

}

}


Branje iz naprave:

import java.io.IOException;
import java.io.InputStream;

public class SerialReader implements Runnable
{
InputStream in;

public SerialReader ( InputStream in )
{
this.in = in;
}

public void run ()
{
byte[] buffer = new byte[1024];
int len = -1;
try
{
while ( ( len = this.in.read(buffer)) > -1 )
{
System.out.print(new String(buffer,0,len));
}
}
catch ( IOException e )
{
e.printStackTrace();
}
}
}


Pisanje v napravo oz pošiljanje komand:

public void run ()
{
System.out.println("Insert command: ");

try {
serialPort.notifyOnOutputEmpty(true);
} catch (Exception e) {
System.out.println("Error setting event notification");
System.out.println(e.toString());
}

System.out.println("Writing \""+messageString+"\" to "+serialPort.getName());
try {
//write to serial port
out.write(messageString.getBytes());
out.close();

} catch (IOException e) {}
}


Blog najdete tudi na dotnet blog


Programiranje Dodatkov Za Word

Avtor boss-tech, 9 Jul 2009, 12:09

V tem članku bom na kratko opisal kako lahko v .net napišemo dodatek oz AddIn za Word. Podobno se naredijo dodatki tudi za ostale Microsoftove programe.

Za AddIn-e potrebujete 2 dodatka (prerequsites): Office 2003 PIAs in VSTO Runtime 2005SE
Ti so potrebni, da lahko uporabnik inštalira dodatek na svojem računalniku.

Najprej odprite Visual Studio. Jaz uporabljam 2008. Pojdite na File-> New-> Project. Potem pa na Visual C# -> Office ter izberiteWord 2003 Add-In.
Seveda lahko izberete tudi novejši addin če to želite.




v Solution Explorerju imam sedaj prikazan naš projekt:



Izberemo ThisAddIn.cs in dobimo kodo:

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}

V metodo Startup dodamo kodo, ki se izvede ob zagonu Add-Ina(npr. klik na gumb), Shutdown pa ko zaključimo.
Sedaj bomo naredili gumb za AddIn in ga dodali v File menu v Word. Čeprav je AddIn za Word 2003 deluje tudi v 2008.

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{

const MsoControlType menuItem = Office.MsoControlType.msoControlButton;
var mainMenuBar = Application.CommandBars.ActiveMenuBar;
mainMenuBar.Reset(); //reset menu bar
var myControl = (Office.CommandBarButton)Application.CommandBars["File"].Controls.Add
(menuItem, missing, missing, 1, true);

myControl.Style = Office.MsoButtonStyle.msoButtonCaption;
myControl.Caption = "My button";
myControl.Tag = "mz button";

//meotda gumba
myControl.Click +=
MyButtonMethod; //ob kliku na gumb se bo sprožila metoda MyButtonMethod

}

private void MyButtonMethod(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
{
MessageBox.Show("To je moj AddIn!");
}

Metoda nam bo ob klicu izpisala tekst... sedaj pritisnemo F5 oz debug in se nam mora odpreti Word.
Kliknemo na File in najti moramo My button.



Kliknemo nanj in potem dobimo message box:



Sedaj lahko s tem dodatkom urejamo tekst, pošiljamo ali kopiramo dokument, ter še marsikaj.

Tako... to je bil na kratko od AddIn-ih za word. Če imate kakšna vprašanja pa kar komentirajte.

Več na mojem DotNetBlogu


Film Šah Mat

Avtor boss-tech, 28 May 2009, 15:29

Na Chanda TV je seda na voljo kratek film skupine Caveman pictures - Šah mat

Vabljeni k ogledu.. klik



o flimu ŠAH MAT (Checkmate)



We are group of four young filmmakers from Maribor, Slovenia: Mitja Mlakar, Mojca Pernat, Robert Ribic and Miha Subic. We are making short films since year 2004 and we already made 17 films, 3 animations and 11 side projects.

Our first film was made on 9th of June 2004 on Pekerska hill in Maribor. This film is called "Speed" and it was awarded on film festival Videomanija 2005. In January 2005 we made our first animated film, called "Hitrost ubija" ("Speed kills"). With 5 awards, including best animated film on film festival Videomanija 2005, is this our most successful project. Through year 2005 we made films "Speed 2", "Speed 3", "Carlijeva kuhinja", "Operacija: Kokos" and "Ordinary day", which are skate,comedy and romantic films. The year 2006 was most of all marked with making documentary films for our school, III.gimnazija Maribor. However we made few other project. We made our 2nd horror film called "Strangers in the night". This film was made spontaneously in the middle of the night without screenplay, nor special cast. We alsaw made our first music video for slovenian music group called Mi2. Music video is for the song "Tarzan". In February 2007 we made film called "Somnium", which is action/comedy genre and in November 2007, we made four 1 minute long films. They were made for ITAK filmfest with mobile phone, but unfortunately none of our films did not won festival. Our latest movie is "Šah mat" which was screened on Festival of Slovenian Film in Portoroz. Music for the film was made by Slovenian music group Rockheads.

All our films are made without any help from experts and we made everything from screenwriting and directing to editing and animating ourselfs. Only music is not our work.

In time of our existence, we have been on many film festivals, screenings and on two film workshops. We won many awards in Slovenia and even in foreign countrys. For future we have many plans which we want to realize.

We want to thank all our friends and everybody who ever helped or supported us.


Moj Projekt: Črna Lista

Avtor boss-tech, 15 Apr 2009, 16:52 in Črna Lista

Črna Lista

Gre za projekt, kjer lahko obiskovalci dodajajo predloge za črno listo, ter glasujejo in komentirajo osebe, ki so že na njej. Vsebuje pa ljudi, ki na kakršenkoli način škodujejo
državi ali prebivalcem. Seveda pa imamo tudi naj Slovence, novice, članke, igro Boj za piranski zaliv, opis zaupnih dokumentov ter še kaj.

Vabljeni

http://crna-lista.info/


Kategorije


Kategorije